ios - 为什么 UIPopoverController 不是 UIViewController 的子类?

标签 ios cocoa-touch uiviewcontroller uipopovercontroller

你能想到 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/

相关文章:

ios - 如何正确定位动画 CAShapeLayer

ios - 如何禁用 UIPageViewController 的滑动手势?

ios - 在 UIWebView 中打开一个 URL

iphone - 为什么我的网络事件图标没有出现在我的 iPhone 应用程序中

iphone - 在 ios 键盘上方显示建议工具栏

ios - 将数据传递到本地 html iOS webview

ios - 尝试背对背呈现 2 个 UIAlertController

ios - 在dismissViewControllerAnimated 之后的presentViewController

android - Ionic 2-无法使用 aar 文件/ios 框架添加自定义 android/ios 插件

同一应用程序的 iPhone 和 iPad 版本?