https://developer.apple.com/library/archive/documentation/General/Conceptual/Devpedia-CocoaApp/MainEventLoop.html

In the main event loop, an application continuously routes 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 for scheduling work and coordinating the receipt 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. What distinguishes 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. It establishes a connection with those underlying system components that are responsible for the delivery 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 application terminates.

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 most appropriate 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 application via 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.

Prerequisite Articles

Related Articles

Definitive Discussion

Event Handling Guide for iOS

Sample Code Projects

(None)

最新文章

  1. Cursor use
  2. [Android]通过js方法回调部分native报错 Web Console: Uncaught TypeError: Object [object Object] has no method 'xxx'
  3. IOS开发的目录结构
  4. ural 1283. Dwarf
  5. [ROS]1 小乌龟
  6. 【转】C#程序打包安装部署之添加注册表项
  7. PLSQL_基础系列10_子查询WITH AS(案例)
  8. defer和async的区别
  9. 使用贝赛尔曲线画扇形、圆形、弧线、多边形,实现App下载时的动画效果demo
  10. android studio1.3安装终于成功
  11. failed to lazily initialize a collection of role
  12. 友盟iOS微信登陆没有回调的原因
  13. Centos6.6安装Nginx
  14. Python知识小点(备注)
  15. DataGridView显示数据库内容及更新内容到数据库
  16. 将本地的项目导入到github仓库总结lxw
  17. b继承a
  18. 40多行python代码开发一个区块链。
  19. python购物车-基础版本
  20. 决策树 Decision Tree

热门文章

  1. checkBox判断是否选中的方法
  2. 动态SQL基本语句用法
  3. 10分钟带你入门git到github
  4. JavaDailyReports10_18
  5. JVM的艺术-对象创建与内存分配机制深度剖析
  6. 自动化运维工具-Ansible之2-ad-hoc
  7. cmake的安装
  8. Head First 设计模式 —— 00. 引子
  9. DEDECMS自动编号(序号)autoindex属性(转)
  10. Ubuntu 一直要求依赖的错误