本文介绍了IO6不调用 - (BOOL)shouldAutorotate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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];
...

在每个 ViewController中我有 UITabBar (我不知道这是否重要)。

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 被调用在视图加载但 shouldAutorotate 没有调用我旋转设备。

我在这里缺少什么?

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

推荐答案

这是因为 UITabBarcontroller UINavigationController 都不是将shouldAutorotate传递给它的可见视图控制器。为了解决这个问题,你可以从那里继承任何的UITabBarController或UINavigationController的转发shouldAutorotate:

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:

在你的子类的UITabBarController添加:

In your subclassed UITabBarController add:

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

在你的子类UINavigationController中添加:

In your subclassed UINavigationController add:

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

这篇关于IO6不调用 - (BOOL)shouldAutorotate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 10:51