我有多个 UIViewController,它们的 View 通过添加 subview 相互嵌套。我只是让我所有的观点都自动改变了方向,除了一个。堆栈末尾的那个。我还意识到 willRotateToInterfaceOrientation 方法不会传播到 subview Controller 。处理这个问题的最佳方法是什么?我应该尝试手动将调用路由到 subview 吗?
不旋转的最终 Controller 取自示例照片查看器应用程序 PhotoViewController,它依赖于调用的 willRotateToInterfaceOrientation 方法。
如有任何帮助,我们将不胜感激。
最佳答案
对于 iOS 4.3 和更早版本,路由对 willRotateToInterfaceOrientation
(和其他此类方法)的调用是完全好的做法。问题是没有 View Controller 是其他 View Controller 的 subview Controller 的概念。
在 iOS 5 中,引入了容器 View Controller 的概念(事实证明 UINavigationController 和 UITabBarController 一直都是特殊的“容器 View Controller ”——请注意,这些 View Controller 已经将这些方法路由到您自己的 View Controller ! ).容器 View Controller 的概念形式化了这种路由方法的想法,例如从父 View Controller 到 subview Controller 的 willRotateToInterfaceOrientation
。
您应该查看“UIViewController”类引用文档的“实现容器 View Controller ”部分。 iOS5 目前处于开发者预览阶段,因此您需要成为注册的 iOS 开发者才能访问它。从 iOS5 开始,这将是解决您所描述问题的首选方法。
关于iphone - 手动路由 willRotateToInterfaceOrientation 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7180605/