Disable rotation for View Controller in Navigation Controller

前端 未结 7 832
闹比i
闹比i 2020-12-19 12:57

First of all, this isn\'t a duplicate. I\'ve looked at all of the questions related to this on SO and none of them work for me. Hopefully it\'s just because I\'m new to iOS

7条回答
  •  有刺的猬
    2020-12-19 13:37

    You have to check in your root view controller is rotation allowed in current top controller and return YES or NO in supportedInterfaceOrientations method. So it should be like the following code in your root controller (adapt the code to your case):

    - (NSUInteger)supportedInterfaceOrientations
    {    
        return [self.navigationController.topViewController supportedInterfaceOrientations];
    }
    

    Then in each view controller add supported interface orientations, for example:

    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

提交回复
热议问题