你能想到 Apple 选择将 UIPopoverController 作为一个普通的 NSObject 子类来实现的具体原因吗?对我来说,一个 UIViewController 子类会更有意义,以实现适当的 UIViewController 包含。
但也许有一些我没有想到的原因,为什么 Apple 聪明的工程师做出了他们的选择?
最佳答案
我认为这是因为,与 UIAlertView 一样,它呈现在一个新的 UIWindow 中,因此 windowLevel 属性保证它呈现在所有内容上。 罢工>
无论是否在新的 UIWindow 中,就 View Controller 包含而言,在 View Controller 中使用复杂的父 subview Controller 容器层次结构应该没有问题UIPopoverController。我在 Pillboxie 中有至少三层嵌套的 View Controller 对于一些弹出窗口,没有任何问题。
更新:我通过在示例项目中记录 View 层次结构的前三层的类来检查层次结构,当弹出窗口可见时如下所示(我的 Root View Controller 有两个 UIButtons):
一个窗口:
_SUBVIEW 类:UIView
___SUBSUBVIEW 类:UIRoundedRectButton
__SUBSUBSUBVIEW 类:UIButtonLabel
___SUBSUBVIEW 类:UIRoundedRectButton
__SUBSUBSUBVIEW 类:UIButtonLabel
_SUBVIEW 类:UIDimmingView
___SUBSUBVIEW 类:_UIPopoverView
__SUBSUBSUBVIEW 类:_UIPopoverStandardChromeView
__SUBSUBSUBVIEW 类:UIView
Apple 的文档指出,UIWindow 中的 Root View Controller 的 View 不应有由其他 View Controller 管理的同级 View ,因为那些同级 View Controller 不会接收旋转事件(请参阅 here,第二个项目符号)。
因此,如果 Apple 将 UIPopoverController 设为 UIViewController 子类,则必须将其添加为 rootViewController 层次结构的子/ subview 。但是,如果 Root View Controller (无论如何都是您的代码)决定呈现一个干扰 UIPopoverController View 层次结构的 View 怎么办? Apple 似乎决定完全管理 UIPopoverController 的呈现,而不是让我们把它搞砸,但他们不必为 UIWindow 的无兄弟 View Controller 政策授予自己异常(exception)。
关于ios - 为什么 UIPopoverController 不是 UIViewController 的子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11986457/