IO6不调用 - (BOOL)shouldAutorotate

111*_*110 2 iphone objective-c uiinterfaceorientation ios ios6

我在我的应用程序中有一些观点,我不想支持方向.在didFinishLaunchingWithOptions我添加导航:

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

    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
...
Run Code Online (Sandbox Code Playgroud)

在每一个ViewControllerUITabBar(我不知道这是否重要).

在第一个视图控制器中我添加:

-(BOOL)shouldAutorotate {
        return NO;
    }

    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
Run Code Online (Sandbox Code Playgroud)

supportedInterfaceOrientations在视图加载时shouldAutorotate调用,但在旋转设备时不调用.
我在这里错过了什么?

Tom*_*cki 15

这是因为既没有UITabBarcontroller也没有UINavigationController将shouldAutorotate传递给它的可见视图控制器.要解决这个问题,你可以继承UITabBarController或UINavigationController,并从那里转发shouldAutorotate:

在你的子类UITabBarController中添加:

- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}
Run Code Online (Sandbox Code Playgroud)

在你的子类UINavigationController中添加:

- (BOOL)shouldAutorotate
{
    return [self.visibleViewController shouldAutorotate];
}
Run Code Online (Sandbox Code Playgroud)