phantomon icon

Autorotation

phantomon | PRO | 10/18/17 07:52:53 PM UTC | 0 ⭐ | 224 👁️ | Never ⏰ | []
Swift |

440 B

|

None

|

0 👍

/

0 👎

override func viewDidLoad() {
    super.viewDidLoad()        
 
    NotificationCenter.default.addObserver(self, selector: #selector(ViewController.rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
 
deinit {
     NotificationCenter.default.removeObserver(self)
}
 
func rotated() {
    if UIDevice.current.orientation.isLandscape {
        print("Landscape")
    } else {
        print("Portrait")
    }
}

Comments