iOS程序的準備工作

?程序啟動的過程
.在桌面找到相應(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)了,那么這個事件就停止傳遞了。

Paste_Image.png

?為什么要使用代理
  為了簡化代碼邏輯(蘋果公司自己設(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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 好奇觸摸事件是如何從屏幕轉(zhuǎn)移到APP內(nèi)的?困惑于Cell怎么突然不能點擊了?糾結(jié)于如何實現(xiàn)這個奇葩響應(yīng)需求?亦或是...
    Lotheve閱讀 59,590評論 51 604
  • 在開發(fā)過程中,大家或多或少的都會碰到令人頭疼的手勢沖突問題,正好前兩天碰到一個類似的bug,于是借著這個機會了解了...
    閆仕偉閱讀 5,684評論 2 23
  • 在iOS開發(fā)中經(jīng)常會涉及到觸摸事件。本想自己總結(jié)一下,但是遇到了這篇文章,感覺總結(jié)的已經(jīng)很到位,特此轉(zhuǎn)載。作者:L...
    WQ_UESTC閱讀 6,250評論 4 26
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,644評論 19 139
  • App Programming Guide for iOS翻譯 https://developer.apple.c...
    鋼鉄俠閱讀 725評論 0 1

友情鏈接更多精彩內(nèi)容