寫API的目的在於作為一個字典的作用。簡單,明了,溫習,復習。 //1.定義一個CGFloat類型的UIWindowLevel,UIWindowLevel分為三種不同選擇,定義了UIWindow不同層級的展示方式,UIWindow在現實的時候會根據三種不同選擇進行不同的排序,即level高的將排在level比他低的層級前面。 typedef CGFloat UIWindowLevel; //2.添加UIScreen屏幕屬性 @property(nonatomic,retain) UIScreen *screen NS_AVAILABLE_IOS(3_2); // default is [UIScreen mainScreen]. changing the screen may be an expensive operation and should not be done in performance-sensitive code //3. UIWindowLevel屬性 @property(nonatomic) UIWindowLevel windowLevel; // default = 0.0 //4.keyWindow是指定的用來接收鍵盤以及非觸摸類的消息,而且程序中每一個時候只能有一個window是keyWindow @property(nonatomic,readonly,getter=isKeyWindow) BOOL keyWindow; //5.設置當前window變成主window - (void)becomeKeyWindow; // override point for subclass. Do not call directly //6.放棄當前主window - (void)resignKeyWindow; // override point for subclass. Do not call directly //7.讓當前window變成keyWindow - (void)makeKeyWindow; //8.讓當前window變成keyWindow,並顯示出來 - (void)makeKeyAndVisible; // convenience. most apps call this to show the main window and also make it key. otherwise use view hidden property //9.設置UIViewController為根控制器 @property(nonatomic,retain) UIViewController *rootViewController NS_AVAILABLE_IOS(4_0); // default is nil //10.當產生一個事件時,先傳遞給UIApplication,而UIAppliaction將這個事件傳遞UIWindow進行處理,然後由UIWindow將這個時間傳遞給特定的對象,即first responder,而UIWindow就是通過sendEvent尋找first responder,經過sendEvent分發到合適的對象,sendEvent就相當於時間的中轉站。 - (void)sendEvent:(UIEvent *)event; // called by UIApplication to dispatch events to views inside the window //11.將當前window一個坐標轉化為相對於另外一個窗口的坐標 - (CGPoint)convertPoint:(CGPoint)point toWindow:(UIWindow *)window; // can be used to convert to another window //12.將另一個窗口的一個坐標轉化為當前窗口的坐標 - (CGPoint)convertPoint:(CGPoint)point fromWindow:(UIWindow *)window; // pass in nil to mean screen //13.轉化當前窗口一個矩形坐標相對於當前窗口的坐標. - (CGRect)convertRect:(CGRect)rect toWindow:(UIWindow *)window; //14.轉化裡面那個外窗口一個矩形坐標相對於當前窗口的坐標 - (CGRect)convertRect:(CGRect)rect fromWindow:(UIWindow *)window; @end //15.定義UIWindow展示優先級不同層次的選擇 ,根據window顯示級別優先的原則,級別高的灰顯示在上面,級別低的在下面,我們程序正常顯示的位於最底層 UIKIT_EXTERN const UIWindowLevel UIWindowLevelNormal; //默認的window就是Normal級別,優先級值這個層次的值為0,通常我們程序的界面都是處於這個Normal級別的 UIKIT_EXTERN const UIWindowLevel UIWindowLevelAlert; //屏幕的statusBar處於中等水平,優先級值為1000 UIKIT_EXTERN const UIWindowLevel UIWindowLevelStatusBar;// alert級別的,通常是UIAlertView和UIAlertSheet這些用來中斷正常流程,提醒用戶等操作的。優先級值為2000.按照這樣說來,alertView彈框出來下面也是一層UIWindow,只不過是優先級最高的alert級別,所以是keyWindow,當前只能交互alert,這就是為什麼彈框出來其他界面都不可交互的原因 //16.接下來是window變化的四個通知 UIKIT_EXTERN NSString *const UIWindowDidBecomeVisibleNotification; //當window顯示就會調用 UIKIT_EXTERN NSString *const UIWindowDidBecomeHiddenNotification; //window被隱藏之後調用,需要注意的是,當程序進入後台時,這兩個通知不會被調用,即使應用轉到後台,窗口不會顯示,窗口應用下的上下文中仍然被認為是可見的 UIKIT_EXTERN NSString *const UIWindowDidBecomeKeyNotification; //window成為主窗口調用 UIKIT_EXTERN NSString *const UIWindowDidResignKeyNotification; //window撤銷主窗口調用 //17. 監聽鍵盤變化的通知 UIKIT_EXTERN NSString *const UIKeyboardWillShowNotification; //當鍵盤將要顯示的時候調用 UIKIT_EXTERN NSString *const UIKeyboardDidShowNotification; //當鍵盤已經顯示的時候調用 UIKIT_EXTERN NSString *const UIKeyboardWillHideNotification; //當鍵盤將要隱藏的時候調用 UIKIT_EXTERN NSString *const UIKeyboardDidHideNotification; //當鍵盤隱藏完畢的時候調用 //18.關於監聽鍵盤通知的一些userInfo消息 UIKIT_EXTERN NSString *const UIKeyboardFrameBeginUserInfoKey NS_AVAILABLE_IOS(3_2); //動畫前鍵盤的位置,包含CGRect的NSValue 可以在通知方法中寫得到位置 CGRect rect = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; UIKIT_EXTERN NSString *const UIKeyboardFrameEndUserInfoKey NS_AVAILABLE_IOS(3_2); //動畫結束後鍵盤的位置 包含CGRect的NSValue UIKIT_EXTERN NSString *const UIKeyboardAnimationDurationUserInfoKey NS_AVAILABLE_IOS(3_0); //動畫的持續時間,數值是NSNumber UIKIT_EXTERN NSString *const UIKeyboardAnimationCurveUserInfoKey NS_AVAILABLE_IOS(3_0); //動畫的曲線類型(UIViewAnimationCurve),數值是NSNumber //19.監聽鍵盤frame大小變化的通知 UIKIT_EXTERN NSString *const UIKeyboardWillChangeFrameNotification NS_AVAILABLE_IOS(5_0); //當鍵盤frame值將要改變的時候調用 UIKIT_EXTERN NSString *const UIKeyboardDidChangeFrameNotification NS_AVAILABLE_IOS(5_0); //當鍵盤frame值已經改變的時候調用 //下面為一些廢棄很久的API,不多做解釋 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);