phantomon

Autorotation

Oct 18th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.44 KB | None | 0 0
  1. override func viewDidLoad() {
  2.     super.viewDidLoad()        
  3.  
  4.     NotificationCenter.default.addObserver(self, selector: #selector(ViewController.rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
  5. }
  6.  
  7. deinit {
  8.      NotificationCenter.default.removeObserver(self)
  9. }
  10.  
  11. func rotated() {
  12.     if UIDevice.current.orientation.isLandscape {
  13.         print("Landscape")
  14.     } else {
  15.         print("Portrait")
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment