Search code examples
iosswiftuiinterfaceorientation

Force orientation to be Portrait for one view and both for another


My design is as follows: Menu -> App -> Back to Menu

I want my Menu to be 'Portrait ONLY'. My AppView can be Portrait & Landscape.

Currently in my MenuController, I have:

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

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

and in my AppView Controller I have:

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

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

However, my Main menu is rotating in all directions. Anything I am missing here? Thanks!


Solution

  • Yes you need to also change it in plist. You change the property in target of the project. Go to Target, in general tab go to deployment info -> device orientation...... Further you need to subclass UINavigationController and override it:

    -(NSUInteger)suppoertedInterfaceOrientations
    {
    return self.topViewController.supportedInterfaceOrientations;
    }
    

    This will make sure that the viewController being displayed by navigation is in syn