Can't restrict UIViewController to Portrait only

狂风中的少年 提交于 2019-12-24 08:39:56

问题


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:


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.



来源:https://stackoverflow.com/questions/22538461/cant-restrict-uiviewcontroller-to-portrait-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!