UIWindow.h详解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#import <Foundation/Foundation.h>//基础框架入口

#import <CoreGraphics/CoreGraphics.h>//绘图入口

#import <UIKit/UIView.h>//视图对象

#import <UIKit/UIApplication.h>//提供iOS程序运行期的协作和控制

#import <UIKit/UIKitDefines.h>//一些宏定义



NS_ASSUME_NONNULL_BEGIN



typedef CGFloat UIWindowLevel;//32位则为float | 64位为double

/*

UIEvent 触摸事件,运动事件

UIScreen 屏幕处理

NSUndoManager 记录撤销,修改操作的消息

UIViewController 视图控制器

*/

@class UIEvent,UIScreen, NSUndoManager,UIViewController;



NS_CLASS_AVAILABLE_IOS(2_0)@interface UIWindow :UIView



@property(nonatomic,strong)UIScreen *screen;

@property(nonatomic)UIWindowLevel windowLevel;

@property(nonatomic,readonly,getter=isKeyWindow)

BOOL keyWindow;

- (void)becomeKeyWindow;

- (void)resignKeyWindow;

- (void)makeKeyWindow;

- (void)makeKeyAndVisible;

@property(nullable,nonatomic,strong)UIViewController *rootViewController NS_AVAILABLE_IOS(4_0); // default is nil



/*

事件拦截分发到指定视图对象

当用户发起一个事件,比如触摸屏幕或者晃动设备,系统产生一个事件,同时投递给UIApplication,而UIApplication则将这个事件传递给特定

UIWindow进行处理(正常情况都一个程序都只有一个UIWindow),然后由UIWindow将这个事件传递给特定的对象(即first responder)并通过响应链

进行处理。虽然都是通过响应链对事件进行处理,但是触摸事件和运动事件在处理上有着明显的不同(主要体现在确定哪个对象才是他们的first

responder):

*/

- (void)sendEvent:(UIEvent *)event;



//窗口坐标系统转化

- (CGPoint)convertPoint:(CGPoint)point toWindow:(nullableUIWindow *)window;//转化当前窗口一个坐标相对另外一个窗口的坐标

- (CGPoint)convertPoint:(CGPoint)point fromWindow:(nullableUIWindow *)window;//转化另外窗口一个坐标相对于当前窗口的坐标

- (CGRect)convertRect:(CGRect)rect toWindow:(nullableUIWindow *)window;//转化当前窗口一个矩形坐标相对另外一个窗口的坐标

- (CGRect)convertRect:(CGRect)rect fromWindow:(nullableUIWindow *)window;//转化另外窗口一个矩形坐标相对于当前窗口的坐标



@end



UIKIT_EXTERN constUIWindowLevel UIWindowLevelNormal;//默认等级

UIKIT_EXTERN constUIWindowLevel UIWindowLevelAlert;//UIAlert等级

UIKIT_EXTERN constUIWindowLevel UIWindowLevelStatusBar;//状态栏等级



UIKIT_EXTERN NSString *const UIWindowDidBecomeVisibleNotification;// nil 通知对象窗口为可见

UIKIT_EXTERN NSString *const UIWindowDidBecomeHiddenNotification; // nil 通知对象窗口为隐藏

UIKIT_EXTERN NSString *const UIWindowDidBecomeKeyNotification; // nil 通知对象窗口为重要

UIKIT_EXTERN NSString *const UIWindowDidResignKeyNotification; // nil 通知对象窗口取消主窗



//当键盘显示或消失时,系统会发送相关的通知:

UIKIT_EXTERN NSString *const UIKeyboardWillShowNotification;//通知键盘对象视图即将加载

UIKIT_EXTERN NSString *const UIKeyboardDidShowNotification;//通知键盘对象视图完全加载

UIKIT_EXTERN NSString *const UIKeyboardWillHideNotification;//通知键盘对象视图即将隐藏

UIKIT_EXTERN NSString *const UIKeyboardDidHideNotification;//通知键盘对象视图完全隐藏



/*

通知消息 NSNotification中的 userInfo字典中包含键盘的位置和大小信息,对应的key为

UIKeyboardFrameBeginUserInfoKey

UIKeyboardFrameEndUserInfoKey

UIKeyboardAnimationDurationUserInfoKey

UIKeyboardAnimationCurveUserInfoKey

UIKeyboardFrameBeginUserInfoKey,UIKeyboardFrameEndUserInfoKey对应的Value是个NSValue对象,内部包含CGRect结构,分别为键盘起始时和终止时的位置信息。

UIKeyboardAnimationCurveUserInfoKey对应的Value是NSNumber对象,内部为UIViewAnimationCurve类型的数据,表示键盘显示或消失的动画类型。

UIKeyboardAnimationDurationUserInfoKey对应的Value也是NSNumber对象,内部为double类型的数据,表示键盘h显示或消失时动画的持续时间



例如,在UIKeyboardWillShowNotification,UIKeyboardDidShowNotification通知中的userInfo内容为

userInfo = {

UIKeyboardAnimationCurveUserInfoKey = 0;

UIKeyboardAnimationDurationUserInfoKey = "0.25";

UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";

UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}";

UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}";

UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";

UIKeyboardFrameChangedByUserInteraction = 0;

UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";

}

在UIKeyboardWillHideNotification,UIKeyboardDidHideNotification通知中的userInfo内容为:

userInfo = {

UIKeyboardAnimationCurveUserInfoKey = 0;

UIKeyboardAnimationDurationUserInfoKey = "0.25";

UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";

UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 372}";

UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 588}";

UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";

UIKeyboardFrameChangedByUserInteraction = 0;

UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";

}

*/

UIKIT_EXTERN NSString *const UIKeyboardFrameBeginUserInfoKey NS_AVAILABLE_IOS(3_2);// NSValue of CGRect

UIKIT_EXTERN NSString *const UIKeyboardFrameEndUserInfoKey NS_AVAILABLE_IOS(3_2);// NSValue of CGRect

UIKIT_EXTERN NSString *const UIKeyboardAnimationDurationUserInfoKeyNS_AVAILABLE_IOS(3_0);// NSNumber of double

UIKIT_EXTERN NSString *const UIKeyboardAnimationCurveUserInfoKey NS_AVAILABLE_IOS(3_0);// NSNumber of NSUInteger (UIViewAnimationCurve)

UIKIT_EXTERN NSString *const UIKeyboardIsLocalUserInfoKey NS_AVAILABLE_IOS(9_0);// NSNumber of BOOL

UIKIT_EXTERN NSString *const UIKeyboardWillChangeFrameNotification NS_AVAILABLE_IOS(5_0);//键盘即将改变布局发出通知

UIKIT_EXTERN NSString *const UIKeyboardDidChangeFrameNotification NS_AVAILABLE_IOS(5_0);//键盘已经改变布局后发出通知

UIKIT_EXTERN NSString *const UIKeyboardCenterBeginUserInfoKey NS_DEPRECATED_IOS(2_0,3_2);

UIKIT_EXTERN NSString *const UIKeyboardCenterEndUserInfoKey NS_DEPRECATED_IOS(2_0,3_2);

UIKIT_EXTERN NSString *const UIKeyboardBoundsUserInfoKey NS_DEPRECATED_IOS(2_0,3_2);



NS_ASSUME_NONNULL_END
文章目录
|