IO6 doesn't call -(BOOL)shouldAutorotate

独自空忆成欢 提交于 2019-11-29 15:45:57

问题


I have some views in my app that I don't want to suport orientation. In didFinishLaunchingWithOptions I add navigation:

...
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController];

    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
...

In each ViewController I have UITabBar (I don't know if this is important).

In the first view controller I add:

-(BOOL)shouldAutorotate {
        return NO;
    }

    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }

supportedInterfaceOrientations is called at the view loading but shouldAutorotate doesn't call as I rotate device.
What am I missing here?


回答1:


It's because neither UITabBarcontroller nor UINavigationController is passing shouldAutorotate to its visible view controller. To fix that you may subclass either UITabBarController or UINavigationController and forward shouldAutorotate from there:

In your subclassed UITabBarController add:

- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}

In your subclassed UINavigationController add:

- (BOOL)shouldAutorotate
{
    return [self.visibleViewController shouldAutorotate];
}



回答2:


in the AppDelegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  // iOS 6
{

return UIInterfaceOrientationMaskAll;


}

in your ViewController:

- (BOOL)shouldAutorotate {
return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}


来源:https://stackoverflow.com/questions/12996293/io6-doesnt-call-boolshouldautorotate

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