IT English Collection(8)之Main event loop

来源:互联网 发布:网络优化工程师工资 编辑:程序博客网 时间:2024/06/05 07:57

1 前言

    今天我们来学习一篇有关IOS事件循环的文章,具体如下。(特此声明:从此篇文章起,其集数与深入学习IOS系列同步,方便大家一起学习,如果错误地方请给与纠正,互相学习,十分感谢!)

2 详述

2.1 正文

    In the main event loop, an application continuouslyroutes incoming events to objects for handling and, as a result of that handling, updates its appearance and state. An event loop is simply a run loop: an event-processing loop forscheduling work andcoordinating thereceipt of events from various input sources attached to the run loop. Every thread has access to a run loop. In all but the main thread, the run loop must be configured and run manually by your code. In Cocoa applications, the run loop for the main thread—the main event loop—is run automatically by the application object. Whatdistinguishes the main event loop is that its primary input source receives events from the operating system that are generated by user actions—for example, tapping a view or entering text using a keyboard.

The Application Object Gets and Dispatches Events
    Just after an application is launched, it sets up the infrastructure for the main event loop. Itestablishes a connection with thoseunderlying system components that are responsible for thedelivery of low-level user events. The application receives these events through an input source installed in the main thread’s run loop. Because the application must handle each event separately, in order of its arrival, these low-level events are placed in a first-in first-out event queue.
Once the initial user interface is on the screen, the application is thereafter driven by external events. The application object obtains the topmost object in the event queue, converts it to an event object (UIEvent on iOS, NSEvent on OS X), and dispatches it to other objects in the application for handling. When the call that dispatched the event returns, the application fetches the next object in the queue and dispatches it. It continues doing this until the applicationterminates.
Core Objects Respond to Events and Draw the User Interface
    When an application is launched, it also sets up a core group of objects that are responsible for drawing the user interface and handling events. These core objects include windows and various kinds of views. When the application object gets an event from the event queue, it dispatches it to the window in which the user event occurred. The window sends the event to the view that is the mostappropriate handler for it:
For multitouch and mouse events, the view is the one under the touch or mouse pointer.
For keyboard, motion, and other events, the view is the first responder.
If this initial view does not handle the event, it can pass it to other views in the applicationvia the responder chain.
    In handling the event, the view often initiates a series of actions that modify the appearance of the application and update the application’s state and data. When these actions have been completed, control returns to the application, which fetches the next event from the event queue.

2.2 生词

route [ruːt] vt. 按某路线发送
schedule ['ʃedjuːl; 'sked-] vt. 安排,计划
coordinate [kəʊ'ɔ:dɪneɪt] vt. 调整;整合
receipt [rɪ'siːt] vt. 收到
various ['veərɪəs] adj. 各种各样的
manually ['mænjuəli] adv. 手动地
distinguishes [dɪ'stɪŋgwɪʃ] vt. 区分;辨别
dispatch [dis'pætʃ] vt. 派遣,派出
infrastructure ['ɪnfrəstrʌktʃə] n. 基础设施;公共建设
establish [ɪ'stæblɪʃ; e-] vt. 建立;创办
underlying [ʌndə'laɪɪŋ] adj. 潜在的;根本的
components [kəm'pəunənt] n. 部件;组件
delivery [dɪ'lɪv(ə)rɪ] n. [贸易] 交付;分娩
thereafter [ðeər'ɑːftə] adv. 其后;从那时以后
topmost ['tɒpməʊst] adj. 最高的;顶端的
terminate ['tɜːmɪneɪt] vt. 使终止;使结束
appropriate [ə'prəʊprɪət] adj. 适当的
via ['vaɪə] prep. 渠道,通过;经由

continuously [kən'tinjuəsli] adv. 连续不断地

3 结语

    以上是所有内容,希望对大家有所帮助。

原创粉丝点击