Can't restrict UIViewController to Portrait on

2019-08-09 04:12发布

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?

1条回答
神经病院院长
2楼-- · 2019-08-09 04:37

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.

查看更多
登录 后发表回答