我有一个UIViewController
详情视图,该视图是从UITableView
中的UINavigationController
推送出来的。在UIViewController
我添加了一些子视图(例如UITextView
,UIImageView
)。
在iOS5
中,如果我的图片视图被放大,我使用此代码停止自动旋转:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (scrollView.isZoomed) {
return NO;
}
else {
return YES;
}
}
我正试图在iOS6
下使用:
- (BOOL)shouldAutorotate {
return FALSE;
}
但是从不调用此方法,应用程序继续旋转。
有人可以帮忙吗?
答案 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