iOS UIWindow

来源:互联网 发布:苹果电脑图片浏览软件 编辑:程序博客网 时间:2024/05/22 00:35

UIWindow是UIView的子类,一个程序至少会创建一个window;

keyWindow:

接收键盘及非触摸事(The key window is the one that is designated to receive keyboard and other non-touch related events. Only one window at a time may be the key window)


firstResponder:

第一响应者(first responder 是处于一个应用程序中的响应者对象(通常是一个UIView对象),该对象被指定为非触摸事件的第一个接收者。一个UIWindow 在消息中给第一响应者发送这些事件,给它处理过程中的第一镜头。要接收这些消息,响应者对象必须实现canBecomeFirstResponder并返回YES;它还必须接收一个becomeFirstResponder消息(可以自我触发)。第一响应者是一个窗口的第一个视图来接收下面这些类型的事件和消息:

§                  运动事件-通过调用 UIResponder 运动处理方法,在“Motion Events”中有详细描述

§                  动作消息-当用户操作一个控件(比如一个按钮或滑动条)时发送并且没有为这个动作消息指定目标

§                  菜单编辑消息-当用户点击编辑菜单的命令时发送 ( “Copy, Cut, and Paste Operations” 有详细描述)

第一响应者在文本编辑中也起作用。一个处于编辑焦点中的文本视图或者文本框被作为第一响应者,这将导致虚拟键盘被呈现出来。

注意: 应用程序必须显式的设置一个第一响应者来处理运动事件,动作消息和菜单编辑消息;UIKit会自动把用户点击的文本框和文本视图设置为第一响应者。

如果第一响应者或者点击检测(hit-test)视图没有处理一个事件,它可能会传递事件(通过消息)给响应链中的下一个响应者,看看它是否能处理。



rootViewController:

The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed. The default value of this property is nil.

window作用:

作为视图view的容器;

传递event;

windowLevel:

Levels are ordered so that each level groups windows within it in front of those in all preceding groups. For example, alert windows appear in front of all normal-level windows. When a window enters a new level, it’s ordered in front of all its peers in that level. The default value is 0.0

UIWindowLevelNormal: 0.0

UIWindowLevelAlert: 2000.0

UIWindowLevelStatusBar: 1000.0


windows事件:

UIWindowDidBecomeVisibleNotification

UIWindowDidBecomeHiddenNotification

UIWindowDidBecomeKeyNotification

UIWindowDidResignKeyNotification


SendEvent:方法

Dispatches events sent to the receiver by the UIApplication object to its views.

UIApplication调用sendEvent发送event到UIWindow。

对于touch事件,UIWindow调用sendEvent发送事件到hitTest withEvent:返回的view中;

对于motion事件和remoteControl事件,UIWindow调用sendEvent发送事件到firstResponder。


原创粉丝点击