在iOS6中不调用shouldAutoRotate方法

时间:2012-11-27 16:10:50

标签: iphone xcode ios5 rotation ios6

我有一个UIViewController详情视图,该视图是从UITableView中的UINavigationController推送出来的。在UIViewController我添加了一些子视图(例如UITextViewUIImageView)。

iOS5中,如果我的图片视图被放大,我使用此代码停止自动旋转:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (scrollView.isZoomed) {
    return NO;
}
else {
    return YES;
}

}

我正试图在iOS6下使用:

实现同样的目标
- (BOOL)shouldAutorotate {
return FALSE;
}

但是从不调用此方法,应用程序继续旋转。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

如果您有导航控制器管理这些视图,则不会调用 shouldAutorotate 方法。您必须继承 UINavigationController 并重写方法 shouldAutorotate supportedIntervalOrientations

来自文档:

  

现在,iOS容器(例如UINavigationController)不会咨询他们的孩子以确定他们是否应该自动旋转

编辑-----

如下面Lomax所述,Apple不鼓励对UINavigationController进行子类化。您应该尝试使用类别(this SO question explains it well):

@implementation UINavigationController 
-(BOOL)shouldAutorotate
{
    // your code
}

-(NSUInteger)supportedInterfaceOrientations
{
    (...)
}

@end