?程序啟動的過程
.在桌面找到相應(yīng)的應(yīng)用的圖標 點擊圖標
.main函數(shù)
?UIApplication類
Every app has exactly one instance of UIApplication
每個應(yīng)用程序都只有一個UIApplication類的實例對象
運行起來的應(yīng)用程序就是一個UIApplication對象。
?UIApplicationMain
創(chuàng)建UIAppication對象的一個單例對象(singleton)
The role of your app’s application object
.handle the initial routing of incoming user events
處理用戶行為的一個循環(huán)
.dispatches action messages forwarded to it by control objects (instances of the UIControl class) to appropriate target objects.
將特定的行為分配給特定的目標對象(將不同的事件傳遞給不同的UI控件)
?Tasks
Getting the App Instance:獲取單例對象
Getting the App Delegate:獲取應(yīng)用程序代理(捕獲程序的狀態(tài))
Getting App Windows:獲取窗口
Controlling and Handling Events:處理事件
Opening a URL Resource:打開外部的APP 資源(Safari)
Configuring the User Notification Setting:配置用戶的通知
Registering for Remote Notifications:遠程通知(QQ消息,更新通知)
Registering for Local Notifications:本地通知(鬧鐘)
Managing Background Execution:管理后臺的執(zhí)行
Managing Home Screen Quick Actions for 3D Touch:快捷方式
Controlling App Appearance:管理程序的外觀(狀態(tài)欄,網(wǎng)絡(luò)指示,方向)
NSStringFromClass將一個類轉(zhuǎn)化為字符串形式
NSStringFromClass([AppDelegate class])
?UIApplicationDelegate
The UIApplicationDelegate protocol defines methods that are called by the singleton UIApplication object in response to important events in the lifetime of your app.
響應(yīng)程序運行過程中發(fā)生的一些重要的事件(程序啟動,進入后臺,激活,內(nèi)存吃緊。。)
The app delegate works alongside the app object to ensure your app interacts properly with the system and with other apps.
應(yīng)用程序代理和app共同運行,確保程序與系統(tǒng)或者其他程序之間的交互
The app delegate is effectively the root object of your app. Like the UIApplication object itself, the app delegate is a singleton object and is always present at runtime.
應(yīng)用程序代理是程序的root對象,整個程序運行過程中都一直存在
App Delegate里面的那些方法應(yīng)該被實現(xiàn)
The app delegate performs several crucial roles:
.It contains your app’s startup code.
可以在代理里面使用代碼進行設(shè)置
a.程序加載起來調(diào)用的第一個方法(配置,注冊服務(wù)器信息,讀取數(shù)據(jù),配置界面)
//還沒有運行到內(nèi)存里面
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions NS_AVAILABLE_IOS(6_0);
//加載好了,需要對顯示的界面進行配置
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions NS_AVAILABLE_IOS(3_0);
It responds to key changes in the state of your app. Specifically, it responds to both temporary interruptions and to changes in the execution state of your app, such as when your app transitions from the foreground to the background.
臨時打斷、狀態(tài)改變
It responds to notifications originating from outside the app, such as remote notifications (also known as push notifications), low-memory warnings, download completion notifications, and more.
外部通知(消息推送、內(nèi)存不夠、后臺下載完成)
registerForRemoteNotificationTypes:
It determines whether state preservation and restoration should occur and assists in the preservation and restoration process as needed.
確定程序的狀態(tài)(數(shù)據(jù))是否應(yīng)該保存或者恢復(fù)
It responds to events that target the app itself and are not specific to your app’s views or view controllers.
響應(yīng)應(yīng)用程序本身的事件
application:openURL:options:
You can use it to store your app’s central data objects or any content that does not have an owning view controller.
保存程序當前的核心數(shù)據(jù)或其他那些沒有viewController保存的數(shù)據(jù)
?UIResponder
The UIResponder class defines an interface for objects that respond to and handle events.
定義了對象響應(yīng)和處理事件的接口
所有能夠處理事件的UI控件都是直接或者間接繼承于UIResponder
兩種主要的事件行為:觸摸事件和運動事件
There are two general kinds of events: touch events and motion events.
?UIEvent
touchesBegan:withEvent:,
touchesMoved:withEvent:,
touchesEnded:withEvent:,
touchesCancelled:withEvent:.
motionBegan:withEvent:,
motionEnded:withEvent:,
motionCancelled:withEvent:.
iOS3.0 canPerformAction:withSender:
iOS 4.0, UIResponder added the remoteControlReceivedWithEvent: method for handling remote-control events.
?Responder Chain響應(yīng)者鏈
輯視圖有層級關(guān)系,后添加的視圖會覆蓋前面的視圖,當一個事件發(fā)生了。最前面的視圖會接收到這個事件,如果這個視圖不響應(yīng),那么繼續(xù)將事件傳遞給后面一層,直到UIWindow,如果都不響應(yīng),那么事件將會被丟棄,這個過程中,只要有一個響應(yīng)了,那么這個事件就停止傳遞了。

?為什么要使用代理
為了簡化代碼邏輯(蘋果公司自己設(shè)計外觀和系統(tǒng),將制造、材料、銷售代理出去,就是為了讓自己專注核心模塊)
繼承可以完成代理的功能(如果使用繼承,相當于蘋果公司自己有自己的制造子公司,材料子公司,銷售子公司,對于自己的管理加大了難度,并且無法專注核心競爭力)
整個應(yīng)用程序只有一個代理(默認系統(tǒng)為我們提供了AppDelegate類)
?UIWindow
manages and coordinates the views an app displays on a device screen
管理和協(xié)調(diào)設(shè)備屏幕上面顯示的視圖
一個應(yīng)用程序一般情況下只有一個window
?UIWindow的功能
.provide an area for displaying its views
提供一片用來顯示視圖的區(qū)域
.distribute events to the views.
分發(fā)事件給視圖
.一個UIWindow對象必須設(shè)置一個主界面
設(shè)置窗口的rootViewController屬性
.顯示窗口
調(diào)用makeKeyAndVisible屬性
?UIScreen
A UIScreen object defines the properties associated with a hardware-based display
定義一些與基于硬件顯示的屬性
如何獲取設(shè)備的主屏幕
[UIScreen mainScreen]
如何獲取一個視圖的矩形坐標
bounds屬性
?各種設(shè)配的尺寸:
4(320 * 480)
5(320 * 568)
6(375 * 667)
6p(414 * 736)