在iOS6中不调用shouldAutoRotate方法 [英] shouldAutoRotate Method Not Called in iOS6

查看:160
本文介绍了在iOS6中不调用shouldAutoRotate方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIViewController 详细信息视图,该视图是从 UINavigationController中的 UITableView 推送的。在 UIViewController 中我添加了许多子视图(例如 UITextView UIImageView )。

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).

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

In iOS5 I used this code to stop autorotation if my picture view was enlarged :

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

}

我试图在 iOS6 下使用以下方式实现相同的目的:

I am trying to achieve the same thing under iOS6 using :

- (BOOL)shouldAutorotate {
return FALSE;
}

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

However this method is never called and the app continues rotating.

任何人都可以帮忙吗?

推荐答案

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

If you have a Navigation Controller managing these views, the shouldAutorotate method won't be called. You would have to subclass UINavigationController and override methods shouldAutorotate and supportedIntervalOrientations.

来自文档:


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

Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate

编辑-----

如下面Lomax所述,不鼓励继承子类UINavigationController苹果。你应该尝试一个类别(这个问题解释得很好):

As mentioned below by Lomax, subclassing UINavigationController is discouraged by Apple. You should try a category instead (this SO question explains it well):

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

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

@end

这篇关于在iOS6中不调用shouldAutoRotate方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆