[英]shouldAutoRotate Method Not Called in iOS6
我有一个UIViewController
详细视图,它是从UINavigationController
的UITableView
推送的。 在UIViewController
我添加了一些子视图(例如UITextView
、 UIImageView
)。
在iOS5
如果我的图片视图被放大,我使用此代码停止自动旋转:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (scrollView.isZoomed) {
return NO;
}
else {
return YES;
}
}
我正在尝试使用以下方法在iOS6
下实现相同的iOS6
:
- (BOOL)shouldAutorotate {
return FALSE;
}
然而,这个方法永远不会被调用,应用程序会继续旋转。
任何人都可以帮忙吗?
如果您有一个 Navigation Controller 管理这些视图,则不会调用shouldAutorotate方法。 您必须继承 UINavigationController并覆盖方法shouldAutorotate和supportedIntervalOrientations 。
从文档:
现在,iOS 容器(例如 UINavigationController)不会咨询他们的孩子来确定他们是否应该自动旋转
编辑 - - -
正如 Lomax 在下面提到的,Apple 不鼓励子类化 UINavigationController。 你应该尝试一个类别( 这个 SO question 很好地解释了它):
@implementation UINavigationController
-(BOOL)shouldAutorotate
{
// your code
}
-(NSUInteger)supportedInterfaceOrientations
{
(...)
}
@end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.