xcode 在 iOS6 中未调用 shouldAutoRotate 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13588325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
shouldAutoRotate Method Not Called in iOS6
提问by GuybrushThreepwood
I have a UIViewController
detail view which is pushed from a UITableView
in a UINavigationController
. In the UIViewController
I add a number of subviews (e.g a UITextView
, UIImageView
).
我有一个UIViewController
从 a UITableView
in a推送的详细视图UINavigationController
。在UIViewController
I 添加多个子视图(例如 a UITextView
, UIImageView
)。
In iOS5
I used this code to stop autorotation if my picture view was enlarged :
在iOS5
我用这个代码,以停止自转,如果我的图片视图被扩大了:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (scrollView.isZoomed) {
return NO;
}
else {
return YES;
}
}
}
I am trying to achieve the same thing under iOS6
using :
我试图在iOS6
using下实现同样的事情:
- (BOOL)shouldAutorotate {
return FALSE;
}
However this method is never called and the app continues rotating.
然而,这个方法永远不会被调用,应用程序会继续旋转。
Can anyone help ?
任何人都可以帮忙吗?
采纳答案by alemangui
If you have a Navigation Controller managing these views, the shouldAutorotatemethod won't be called. You would have to subclass UINavigationControllerand override methods shouldAutorotateand supportedIntervalOrientations.
如果您有一个 Navigation Controller 管理这些视图,则不会调用shouldAutorotate方法。您必须继承 UINavigationController并覆盖方法shouldAutorotate和supportedIntervalOrientations。
From the docs:
从文档:
Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate
现在,iOS 容器(例如 UINavigationController)不会咨询他们的孩子来确定他们是否应该自动旋转
Edit-----
编辑 - - -
As mentioned below by Lomax, subclassing UINavigationController is discouraged by Apple. You should try a category instead (this SO question explains it well):
正如 Lomax 在下面提到的,Apple 不鼓励子类化 UINavigationController。你应该尝试一个类别(这个 SO question 很好地解释了它):
@implementation UINavigationController
-(BOOL)shouldAutorotate
{
// your code
}
-(NSUInteger)supportedInterfaceOrientations
{
(...)
}
@end