Search code examples
swiftxcodeorientationshouldautorotate

cannot get shouldautorotate to fire when changing orientation


I'm developing an app with Xcode9 using Swift4 and it was originally intended for just iPads but now needs to run on phones too. I need to lock the phones to Portrait and iPads remain Portrait/Landscape.

I've done this before using the shouldautorotate function and returning true or false depending on the device as below.

override func shouldAutorotate() -> Bool {
   return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
   return UIInterfaceOrientationMask.all
}

However, when I change the orientation it does not fire. Is this another depreciated method and if so how do I restrict the orientation now?


Solution

  • After much googling, this worked for me

    https://stackoverflow.com/questions/38969419/ios-how-can-enable-or-disable-rotate-on-each-uiviewcontroller