在选项卡栏控制器的层次结构内旋转视图控制器->导航控制器->查看控制器

在选项卡栏控制器的层次结构内旋转视图控制器->导航控制器->查看控制器

问题描述:

我的应用程序具有如下设置的视图控制器层次结构:

My app has a view controller hierarchy set up like this:

UITabBarController
    |
    UINavigationController
    |  |
    |  UIViewController
    |
    UINavigationController
       |
       UIViewController

此层次结构中的所有视图控制器都覆盖该方法:

All of my view controllers that are within this hierarchy override the method:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

并返回YES-因此,视图控制器应该能够旋转至任何旋转-甚至可以上下颠倒.

and return YES - therefore the view controller should be able to rotate to any rotation - even upside down.

但是,在此设置中,没有一个视图控制器成功旋转.我的印象是,如果导航和标签栏控制器的视图控制器响应旋转,它们将旋转.

However, within this setup none of the view controllers successfully rotate. I was under the impression that navigation and tab bar controllers would rotate if their view controllers respond to rotating.

为什么我的视图控制器不旋转?

Why won't my view controllers rotate?

我能够使它们旋转的唯一方法是对UINavigationController进行子类化并覆盖它的shouldAutorotate方法,但这对我来说是不必要的,我想知道是否有一些我想念的东西工作.

The only way I've been able to get them to rotate is by subclassing UINavigationController and overriding it's shouldAutorotate method, but this feels unnecessary to me and I was wondering if there's something I've missed to make this work.

根据用户体验编码方法:

According to the User Experience Coding How-to:

如果还使用工具栏,则每个工具栏项的视图控制器必须实现shouldAutorotateToInterfaceOrientation:方法,并为要支持的每个方向返回YES.如果您有用于工具栏项目的导航控制器,则该导航控制器的根视图控制器必须实现shouldAutorotateToInterfaceOrientation:方法并返回YES.

If you are also using a toolbar, the view controller for each toolbar item must implement the shouldAutorotateToInterfaceOrientation: method and return YES for each of the orientations you wish to support. If you have a navigation controller for a toolbar item, the root view controller of that navigation controller must implement the shouldAutorotateToInterfaceOrientation: method and return YES.

上面写着工具栏"-但是我认为这是一个错字,可能应该是标签栏".

It says 'toolbar' - but I think this is a typo and is probably supposed to be 'tab bar'.

因此,看来我正确实现了这一点,但我的控制器仍然无法自动旋转.

So it seems that I'm implementing this correctly, yet my controllers still do not auto rotate.

我遇到了这个问题,但我不记得它发生的确切原因.标签栏控制器要求其所有视图控制器在被询问要旋转到该特定方向时对是"做出响应.

I've run into this problem, but I can't remember the exact reason it occurred. The tab bar controller requires all of its view controllers to respond YES when asked about a particular orientation for it to rotate to that orientation.

如果以模态表示,则与基础VC系统似乎无关紧要.

If presented modally, it seems like it doesn't matter about the underlying VC system.

我已经创建了一个测试来显示此内容( RotationTest在GitHub上),但似乎所有这些工作.希望我能记得为什么我在某个时候失败了.

I have created a test to show this (RotationTest on GitHub), but it all seems to be working. Hopefully I can remember why I was failing with this one at some point.