Eli Waxman
Eli Waxman

Reputation: 2897

Can't restrict UIViewController to Portrait only

I'm embedding my app in a UINavigationController, I want most of myViewControllers except one to be Portrait, I've read a lot of questions but could not find a correct answer that works for me.

In my target I'm selecting Device Orientation : Portrait, Landscape Right

I'm adding this to my first ViewController:

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
    return (UIInterfaceOrientationPortrait);
}

But when I rotate the device left the ViewController rotates as well. Why is it rotating?

Upvotes: 1

Views: 345

Answers (1)

matt
matt

Reputation: 535316

You can't easily do in iOS 7 what you're describing. A UINavigationController does not consult its children as to what rotations they like; whatever the permitted rotations of the UINavigationController, those are the permitted rotations of the app, regardless of which child happens to be showing at that moment.

The only really legal and built-in way to force rotation is to use a presented ("modal") view controller that takes over the screen. Its rotation settings are consulted because it is now in charge of the screen.

Upvotes: 1

Related Questions