1
특정 ViewController에서 방향 변경을 감지하려고합니다. 알림 및 사용자 지정 함수를 사용합니다. 알림이 변경 될 때마다 iPhone 7 (iOS 10.2 실행)을 사용하면 회전 된 기능이 호출됩니다. 그러나 iPhone 6 (실행 9.3) 또는 iPhone 6 (10.0 실행 중)을 사용하는 동안 화면이로드 될 때 기능은 , 전화 번호는으로 만 호출되지만 전화를 돌릴 때는 그렇지 않습니다.UIDeviceOrientationDidChange는 iPhone 7에서만 작동합니다.
코드 :
func rotated() {
if UIDevice.current.orientation.isLandscape {
print("Landscape")
} else {
print("Portrait")
}
}
override func viewDidLoad() {
super.viewDidLoad()
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}