为什么 UIWindow 既是 UView 的子级又是父级?
UIKit 参考资料称 UIView 是 UIWindow 的超类,但尽管有这种血统,UIWindow 实际上管理 UIView。 这对我来说听起来很不寻常。
有谁知道这对软件设计有何意义?
非常感谢。
编辑:
我阅读了 iPhone 编程指南中的相关段落。 但我不明白为什么他们会做相反的事情:让 UIWindow 成为 UIView 的父级。 一定有什么事情迫使 Apple 以这种方式设计类层次结构。
The UIKit reference says UIView is a superclass of UIWindow, but despite of this parentage, a UIWindow actually manages UIViews. This sounds so unusual to me.
Does anyone know what the significants of this are in terms of software design?
Many thanks.
EDIT:
I read the related paragraph in the iPhone programming guide. Yet I couldn't see why they do the reverse: let UIWindow be the parent of UIView. There must have been some thing that forced Apple to design the class hierarchy this way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 http://developer.apple.com /iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html
编辑:
UIView 是通用的(提供用于创建所有类型的视图并访问其属性的通用方法。)而 UIWindow 更具体(类定义管理和协调应用程序在屏幕上显示的窗口的对象。)
我知道有点模糊,我想只有苹果知道这个层次结构的确切原因。
http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/occ/cl/UIWindow
和
http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView
from http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html
EDIT:
the UIView is something generic (provides common methods you use to create all types of views and access their properties. ) while UIWindow is more concrete (class defines objects that manage and coordinate the windows an application displays on the screen.)
I know is a little vague and I think only apple would know the exact reason for this hierarchy.
http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/occ/cl/UIWindow
and
http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView
因为这样每个 UIView 都会具有仅对窗口有意义的(继承的)属性和行为。 那是错误的。
另一种方式更有意义:窗口在视图之上添加行为。 因此它可以绘制、有边界、包含其他视图等。但它通过例如知道如何渲染到显示器来扩展这一点。
在 MacOS X 中,NSWindows 不是视图。 它们包含一个“根视图”,称为 contentView。 iOS 窗口是 NSWindow + 其根视图的组合。
Because then every UIView would have (inherited) properties and behavior that only makes sense for windows. That's just wrong.
The other way around makes more sense: a window adds behavior on top of views. So it can draw, have bounds, contain other views, etc. But it extends this with, e.g., knowing how to render to the display.
In MacOS X, NSWindows are not views. They contain a "root view", called the contentView. iOS windows are a composition of NSWindow + its root view.
每个常规 UIView 包括主窗口的根视图都应该有一个父视图。 UIWindow 继承 UIView 来执行视图层次结构中父视图的职责。
UIWindow 不是常规视图,它有自己的 UIView 接口方法实现。
Each regular UIView including the main window’s root view should have a parent view. UIWindow inherits UIView to perform duties of a parent view in a view hierarchy.
UIWindow is not regular view and has its own implementations of methods from UIView's interface.