iOS 7 - Restrict landscape orientation only in one view controller

后端 未结 2 959
遇见更好的自我
遇见更好的自我 2020-12-03 18:29

I need to open the first view controller only in portrait mode. As the rest view controllers will use both orientation. So i have added both orientation in plist file.

相关标签:
2条回答
  • 2020-12-03 19:02

    This will lock your View Controller's Orientation in Portrait Mode:

    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    0 讨论(0)
  • 2020-12-03 19:19

    Fixed it simply by creating UINavigationController class and overriding

    -(NSUInteger)supportedInterfaceOrientations
    {
        AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
        if(appDelegate.isOrientationOn) {
            return UIInterfaceOrientationMaskAll;
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    

    Use this custom navigation controller class in root window and that's all.

    0 讨论(0)
提交回复
热议问题