【发布时间】:2012-01-18 14:37:10
【问题描述】:
我创建了一个继承自 UIViewController 的自定义 TabBarController(不是 UITabBarController,因为它不用于子类化)。除了方向支持外,一切正常。
我的 TabBarController 在我的 UIWindow 上设置为 rootViewController,并包含 UIViewControllers 的内部数组。就我而言,我已将 UINavigationControllers 添加为每个选项卡的根目录。
当将新的 UIViewController 推送到 TabBarController 中的任何 UINavigationController 时,我会调用 shouldAutorotateToInterfaceOrientation,这一切都很好,因为在这里我可以设置哪个 UIViewController 应该支持哪个方向(如 Apple 文档中所述)。
但是,当我通过按 UINavigationBar 中的后退按钮返回时,我没有收到对 shouldAutorotateToInterfaceOrientation 的调用,因此我们显示的视图最终会以错误的方向结束。
我通过将自定义 TabBarController 替换为 UITabBarController 进行了快速测试,并且在按下后退按钮时收到了对 shouldAutorotateToInterfaceOrientation 的调用,所以这里肯定有问题,但我不知道是什么。
为什么我没有接到 shouldAutorotateToInterfaceOrientation 的调用? UITabBarController 是否在做我错过的事情?
这里有人遇到过同样的问题吗?你有什么想法值得尝试,因为我已经没有想法了。
编辑
通过使用 iOS5 容器视图控制器将 TabBarController 中的每个 UIViewController 添加为子项来解决此问题。
使用此方法将 UIViewController 添加为子项:addChildViewController 然后自动覆盖ForwardAppearanceAndRotationMethodsToChildViewControllers 并返回YES。
现在您应该在 UIViewControllers 中获得 shouldAutorotateToInterfaceOrientation 回调
【问题讨论】:
标签: iphone objective-c uitabbarcontroller uiinterfaceorientation