gpt4 book ai didi

iphone - 在选项卡栏 Controller -> 导航 Controller -> View Controller 的层次结构中旋转 View Controller

转载 作者:行者123 更新时间:2023-12-03 19:42:16 26 4
gpt4 key购买 nike

我的应用程序的 View Controller 层次结构设置如下:

UITabBarController
|
UINavigationController
| |
| UIViewController
|
UINavigationController
|
UIViewController

此层次结构中的所有 View Controller 都会覆盖该方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

并返回YES - 因此 View Controller 应该能够旋转到任何旋转 - 甚至颠倒。

但是,在此设置中,没有一个 View Controller 能够成功旋转。我的印象是,如果导航和标签栏 Controller 的 View Controller 响应旋转,它们就会旋转。

为什么我的 View Controller 不旋转?

我能够让它们旋转的唯一方法是子类化 UINavigationController 并覆盖它的 shouldAutorotate 方法,但这对我来说没有必要,我想知道如果我遗漏了一些东西来完成这项工作。

编辑:

根据用户体验编码指南:

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.

它说“工具栏” - 但我认为这是一个拼写错误,可能应该是“选项卡栏”。

看来我正确地实现了这一点,但我的 Controller 仍然不自动旋转。

最佳答案

我遇到了这个问题,但我不记得发生它的确切原因。当询问特定方向时,选项卡栏 Controller 要求其所有 View Controller 响应"is",以便旋转到该方向。

如果以模态方式呈现,似乎与底层 VC 系统无关。

我创建了一个测试来显示这一点( RotationTest on GitHub ),但这一切似乎都有效。希望我能记得为什么我在某个时候失败了。

关于iphone - 在选项卡栏 Controller -> 导航 Controller -> View Controller 的层次结构中旋转 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4843460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com