Swift 3:
Add observer in UIDeviceOrientationDidChange in viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(orientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
The selection method is as follows:
func orientationChanged(notification: Notification) {
}
Do not forget to add Remove observer using deinit method
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
source
share