0
votes

I have a storyboard app that is almost always in portrait. I do have one Navigation Controller (with 2 view controllers) that needs to be in landscape mode. It connects back to the main tab controller of the app, and all other view controllers and nav controllers in the app need to stay in portrait mode. I've tried setting orientation to landscape and allowing right and left orientations, but this unlocks all of the viewcontrollers to shift to landscape mode. Is there a way to allow only those 2?

Thanks for any help! Ben

2

2 Answers

1
votes

You have to subclass -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation in every single viewcontroller of your app and only allow it for the 2 view controllers. But for your tab bar, you need to also set it to YES when you are presenting those view controllers (you probably need to subclasse the tabbar to do that) and NO otherwise

1
votes

First of all, don't subclass UINavigationController !

For only LandScape Orientation use this in the ViewController Class that needs to be in Landscape:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

This will keep your view only in Landscape Mode. Don't make a subclass of UINavigationController to put the snippet above in it ! It will cause all your views to remain locked in landscape orientation !

Hope that helps you out :) !