디바이스 회전시 NotificationCenter 를 이용해서 디바이스 방향 이벤트 체크

 
 deinit {
    NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
}
 
 override func viewDidLoad() {
     super.viewDidLoad()
     NotificationCenter.default.addObserver(self, selector: #selector(self.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
 }
 
// 디바이스 회전시 이벤트 발생
@objc func rotated() {
    if UIDevice.isLandscape() {    // 소스추가 : https://limdongo.tistory.com/13
        print("Landscape")
     } else {
        print("Portrait")
     }
}
 

+ Recent posts