Lock the orientation of ViewController

前端 未结 1 1210
轻奢々
轻奢々 2021-01-03 06:29

I have app that supports all kind of orientations, however i want certain viewControllers to support only landscape and few to lock on Potrait Mode. How can i do that, I hav

相关标签:
1条回答
  • 2021-01-03 06:47

    All view controllers pushed on to the same navigation controller must support the same orientation. Specifically, I believe that only the root view controller shouldAutorotateToInterfaceOrientation is ever taken into account. You can have a look at this S.O. post for a sort of workaround; or at this one for a different approach that could be of help.

    The second post I linked above suggests using this definition for shouldAutorotateToInterfaceOrientation you might tweak it for your case:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
      {   
      if ([self.selectedViewController isKindOfClass:[UINavigationController class]]) {
        UIViewController *rootController = [((UINavigationController *)self.selectedViewController).viewControllers objectAtIndex:0];
        return [rootController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
      }
      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
    
    0 讨论(0)
提交回复
热议问题