gpt4 book ai didi

iphone - 为什么 UIWindow 既是 UView 的子级又是父级?

转载 作者:行者123 更新时间:2023-12-03 18:58:25 26 4
gpt4 key购买 nike

UIKit 引用文献说 UIView 是 UIWindow 的父类(super class),但尽管有这种血统,UIWindow 实际上管理 UIView。这对我来说听起来很不寻常。

有谁知道这对软件设计有何意义?

非常感谢。

编辑:
我阅读了 iPhone 编程指南中的相关段落。但我不明白为什么他们会做相反的事情:让 UIWindow 成为 UIView 的父级。肯定有什么事情迫使 Apple 以这种方式设计类层次结构。

最佳答案

来自 http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html

One thing that experienced Mac OS X developers may find unusual about the UIWindow class is its inheritance. In Mac OS X, the parent class of NSWindow is NSResponder. In iPhone OS, the parent class of UIWindow is UIView. Thus, in iPhone OS, a window is also a view object. Despite its parentage, you typically treat windows in iPhone OS the same as you would in Mac OS X. That is, you typically do not manipulate the view-related properties of a UIWindow object directly.

编辑:

UIView 是通用的(提供用于创建所有类型的 View 并访问其属性的通用方法。)而 UIWindow 则更具体(类定义管理和协调应用程序在屏幕上显示的窗口的对象。)

我知道有点模糊,我认为只有苹果知道这个层次结构的确切原因。

http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/occ/cl/UIWindow

The UIWindow class defines objects (known as windows ) that manage and coordinate the windows an application displays on the screen. The two principal functions of a window are to provide an area for displaying its views and to distribute events to the views.

http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView

The UIView class provides common methods you use to create all types of views and access their properties. For example, unless a subclass has its own designated initializer, you use the initWithFrame: method to create a view. The frame property specifies the origin and size of a view in superview coordinates. The origin of the coordinate system for all views is in the upper-left corner.

UIView objects are arranged within an UIWindow object, in a nested hierarchy of subviews. Parent objects in the view hierarchy are called superviews, and children are called subviews. A view object claims a rectangular region of its enclosing superview, is responsible for all drawing within that region, and is eligible to receive events occurring in it as well. Sibling views are able to overlap without any issues, allowing complex view placement.

关于iphone - 为什么 UIWindow 既是 UView 的子级又是父级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/830785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com