iOS程序的准备工作

程序启动的过程
.在桌面找到相应的应用的图标 点击图标
.main函数

UIApplication类
  Every app has exactly one instance of UIApplication
  每个应用程序都只有一个UIApplication类的实例对象
  运行起来的应用程序就是一个UIApplication对象。

UIApplicationMain
  创建UIAppication对象的一个单例对象(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:管理程序的外观(状态栏,网络指示,方向)

NSStringFromClass将一个类转化为字符串形式
  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.
  响应程序运行过程中发生的一些重要的事件(程序启动,进入后台,激活,内存吃紧。。)

The app delegate works alongside the app object to ensure your app interacts properly with the system and with other apps.
  应用程序代理和app共同运行,确保程序与系统或者其他程序之间的交互

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.
  应用程序代理是程序的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,如果都不响应,那么事件将会被丢弃,这个过程中,只要有一个响应了,那么这个事件就停止传递了。

Paste_Image.png

为什么要使用代理
  为了简化代码逻辑(苹果公司自己设计外观和系统,将制造、材料、销售代理出去,就是为了让自己专注核心模块)
 继承可以完成代理的功能(如果使用继承,相当于苹果公司自己有自己的制造子公司,材料子公司,销售子公司,对于自己的管理加大了难度,并且无法专注核心竞争力)

整个应用程序只有一个代理(默认系统为我们提供了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)
6p(414 * 736)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335

推荐阅读更多精彩内容

  • 好奇触摸事件是如何从屏幕转移到APP内的?困惑于Cell怎么突然不能点击了?纠结于如何实现这个奇葩响应需求?亦或是...
    Lotheve阅读 56,234评论 51 598
  • 在开发过程中,大家或多或少的都会碰到令人头疼的手势冲突问题,正好前两天碰到一个类似的bug,于是借着这个机会了解了...
    闫仕伟阅读 5,276评论 2 23
  • 在iOS开发中经常会涉及到触摸事件。本想自己总结一下,但是遇到了这篇文章,感觉总结的已经很到位,特此转载。作者:L...
    WQ_UESTC阅读 5,980评论 4 26
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,497评论 18 139
  • App Programming Guide for iOS翻译 https://developer.apple.c...
    鋼鉄侠阅读 580评论 0 1