Only allow landscape on some views

In my current app the clients wants the vast majority of the app to only support Portrait mode, but on one of the view controllers he wants it to support either Portrait or Landscape. I'm struggling to figure out how to make that happen. Even if I return portrait only from soething like supportedInterfaceOrientations it's still allowing those view controllers to display in landscape mode.


I implemented both supportedInterfaceOrientations and shouldAutorotate, and I also added an extension to UINavigationController so that its shouldAutorotate calls the visible view controller's method.

Detect the UI's (not the device) current orientation, if/else and all that, then reload the desired view to whichever you want. Just remember you can't boot an iPhone app into landscape, as I recall.


Example, if Swift is ok: swiftiostutorials.com/ios-orientations-landscape-orientation-one-view-controller/

I've implemented a subclass of UINavigationController to use in most instances -


class PortraitNavigationController: UINavigationController {

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

return [UIInterfaceOrientationMask.PortraitUpsideDown, UIInterfaceOrientationMask.Portrait]

}

}


and I also have a subclass of UIViewController that I use for analytics, and in there I have -


override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown]

}


This works throughout my app and allows the one or two landscape controllers I have to rotate as needed.

Only allow landscape on some views
 
 
Q