標籤:
UIAppliacation類
每個應用程式都只有一個UIApplication類的執行個體對象
運行起來的應用程式就是一個UIApplication對象
UIApplicationMain
建立UIApplication對象的一個單例對象(singleton)
The role of your app’s application object
.handle the initial routing of incoming user events
處理使用者行為的一個迴圈
.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:擷取應用程式代理程式(捕獲程式的狀態)
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:管理背景執行
Managing Home Screen Quick Actions for 3D Touch:捷徑
Controlling App Appearance:管理程式的外觀(狀態列,網路指示,方向)
NSStringFronClass將一個類轉化為字串形式
NSStringFronClass([AppDelegate class])
UIApplicationDelegate 響應程式運行過程中發生的一些重要的事件(程式啟動,進入後台,啟用,記憶體吃緊。。)
應用程式代理程式和app共同運行,確保程式與系統或者其他程式之間的互動
應用程式代理程式是程式的root對象,整個程式運行過程中都一直存在
App Delegate裡面的那些方法應該被實現
The app delegate performs several crucial roles:
- .It contains your app’s startup code.
- 可以在代理裡面使用代碼進行設定
a.程式載入起來調用的第一個方法(配置,註冊伺服器資訊,讀取資料,配置介面)
//還沒有運行到記憶體裡面
- - (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.
- 臨時打斷、狀態改變
- 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.
- 外部通知(訊息推送、記憶體不夠、後台下載完成)
- registerForRemoteNotificationTypes:
- It determines whether state preservation and restoration should occur and assists in the preservation and restoration process as needed.
- 確定程式的狀態(資料)是否應該儲存或者恢複
- It responds to events that target the app itself and are not specific to your app’s views or view controllers.
- 響應應用程式本身的事件
- 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.
- 儲存程式當前的核心資料或其他那些沒有viewController儲存的資料
UIResponder
The UIResponder class defines an interface for objects that respond to and handle events.
定義了對象響應和處理事件的介面
所有能夠處理事件的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響應者鏈
輯視圖有層級關係,後添加的視圖會覆蓋前面的視圖,當一個事件發生了。最前面的視圖會接收到這個事件,如果這個視圖不響應,那麼繼續將事件傳遞給後面一層,直到UIWindow,如果都不響應,那麼事件將會被丟棄,這個過程中,只要有一個響應了,那麼這個事件就停止傳遞了。
為什麼要使用代理
為了簡化代碼邏輯(蘋果公司自己設計外觀和系統,將製造、材料、銷售代理出去,就是為了讓自己專註核心模組)
繼承可以完成代理的功能(如果使用繼承,相當於蘋果公司自己有自己的製造子公司,材料子公司,銷售子公司,對於自己的管理加大了難度,並且無法專註核心競爭力)
整個應用程式只有一個代理(預設系統為我們提供了AppDelegate類)
UIWindow
manages and coordinates the views an app displays on a device screen
管理和協調裝置螢幕上面顯示的視圖
一個應用程式一般情況下只有一個window
UIWindow的功能
.provide an area for displaying its views
提供一片用來顯示視圖的地區
.distribute events to the views.
分發事件給視圖
.一個UIWindow對象必須設定一個主介面
設定視窗的rootViewController屬性
.顯示視窗
調用makeKeyAndVisible屬性
UIScreen
A UIScreen object defines the properties associated with a hardware-based display
定義一些與基於硬體顯示的屬性
如何擷取裝置的主畫面
[UIScreen mainScreen]
如何擷取一個視圖的矩形座標
bounds屬性
各種設配的尺寸:
4(320 * 480)
5(320 * 568)
6(375 * 667)
6+(414 * 736)
iOS準備程式