根据现在的理解,我把event处理分为5部分,第一是,Event处理的Architecture;第二是,Event的Dispatch到first responder之前; 第三是,Event从first responder出来后;第四是,Action与Event的关系;第五是,Apple Event的处理。

1. Event Handling Architecture

下面这张图解释了在MacOSX上event处理的过程。

Before it dispatches an event to an application, the window server processes it in various ways; it time-stamps it, annotates it with the associated window and process port, and possibly performs other tasks as well. As an example, consider what happens when a user presses a key. The device driver translates the raw scan code into a virtual key code which it then passes off (along with other information about the key-press) to the window server in an event record. The window server has a translation facility that converts the virtual key code into a Unicode character.

In OS X, events are delivered as an asynchronous stream. This event stream proceeds “upward” (in an architectural sense) through the various levels of the system—the hardware to the window server to the Event Manager—until each event reaches its final destination: an application. As it passes through each subsystem, an event may change structure but it still identifies a specific user action.

在event到达Window Server之后,就等着发给各个Application去处理了,如果一个App是基于Cocoa的,它会使用Run Loop从Window Server中获取应该由本App处理的event。

从这个图可以看出,每个应用有一个Event Source与之对应。Event Source中有个Mach port用于从Window Server接收Event,然后存放在一个队列中。每个应用的Main run Loop是一个只负责从event source中取 event,如果没有event,Run Loop就会Block住,一直等到有event为止。之所以这里有个Main run loop是因为,在Cocoa应用中,每个线程都有一个run loop,主线程的run loop叫main run loop。Run loop就是一个NSRunLoop对象。Apple event一会通过Run Loop进入一个App,详细可以见Apple Event部分的描述。

2. Event Dispatch : Arriving at First Responder;

3. Event Dispatch: After First Responder;

4. Action

参考文档

1. Cocoa Event Handling Guide: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW2

2. Event Handling Guide for iOS:https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html#//apple_ref/doc/uid/TP40009541-CH4-SW2

3. Mac vs. iOS event 比较:https://developer.apple.com/library/ios/documentation/general/conceptual/Devpedia-CocoaApp/Responder.html

理解Mac和iOS中的 Event 处理的更多相关文章

  1. iOS中多线程原理与runloop介绍

    一.线程概述 有些程序是一条直线,起点到终点:有些程序是一个圆,不断循环,直到将它切断.直线的如简单的Hello World,运行打印完,它的生命周期便结束了,像昙花一现那样:圆如操作系统,一直运行直 ...

  2. IOS中的多线程和NSRunLoop概述(转载)

    线程概述 有些程序是一条直线,从起点到终点,如Hello World,运行打印完,它的生命周期便结束了:有些程序是一个圆,不断循环,直到将它切断,如操作系统,一直运行直到你关机.  一个运行着的程序就 ...

  3. 在Quick-cocos2dx中使用云风pbc解析Protocol Buffers,支持win、mac、ios、android

    本例主要介绍 如何将 pbc 集成到quick-cocos2dx框架中,让我们的cocos2dx客户端Lua拥有编解码Protocol Buffers能力. 参考: 云风pbc的用法: http:// ...

  4. [NodeJs系列][译]理解NodeJs中的Event Loop、Timers以及process.nextTick()

    译者注: 为什么要翻译?其实在翻译这篇文章前,笔者有Google了一下中文翻译,看的不是很明白,所以才有自己翻译的打算,当然能力有限,文中或有错漏,欢迎指正. 文末会有几个小问题,大家不妨一起思考一下 ...

  5. iOS中web app调试(mac)

    原文 iOS中web app调试(mac).md 目录 一.真机联调配置 二.mac上Safari配置及真机联调 三.iOS模拟器使用 四.在iOS模拟器中安装app 近期公司vue项目开发,目的是一 ...

  6. iOS中的堆(heap)和栈(stack)的理解

    操作系统iOS 中应用程序使用的计算机内存不是统一分配空间,运行代码使用的空间在三个不同的内存区域,分成三个段:“text segment “,“stack segment ”,“heap segme ...

  7. iOS中 常用的mac终端指令汇总 技术分享

    通常情况下,只有高端用户才会经常用到终端应用.这并不意味着命令行非常难学,有的时候命令行可以轻松.快速的解决问题.相信所有Mac用户都尝试过命令行,今天为大家带来9个非常实用的命令行操作.一些命令行需 ...

  8. IOS中调用系统的电话、短信、邮件、浏览功能

    iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...

  9. iOS中数据库应用基础

    iOS 数据库入门 一.数据库简介 1.什么是数据库? 数据库(Database) 是按照数据结构来组织,存储和管理数据的仓库 数据库可以分为2大种类 关系型数据库(主流) PC端 Oracle My ...

随机推荐

  1. Docker 使用指南 (一)—— 基本操作

    版权声明:本文由田飞雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/98来源:腾云阁 https://www.qcloud ...

  2. java 导入包(误区)

    java的导入包语句的作用仅仅是简化书写,很多时候我们都误以为是将一个类导入到内存中. 如果是这样,那么运行的效率会很慢.

  3. css读书笔记1:HTML标记和文档结构

    块级元素和行内元素:块级元素:上下堆叠,每个块级元素都独立占一行.块级元素的盒子宽度与父元素同宽.行内元素:左右堆叠,只有在空间不足的情况下才会折到下一行显示.行内元素的盒子会收缩包裹其内容,并尽可能 ...

  4. 【Problem solved】发现输入法都是仅桌面使用,无法输入中文时

    你打开命令提示符输入CTFMON就可以啦.

  5. 设置westorm自动代码提示

    打开settings 然后在js文件下 打出co  按TAB键就出现了color了

  6. jQuery用户从服务器端注册登录

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. js数据类型和关系运算语法

    var box=; alert(typeof box); //box是Undefined类型,值是undefined,类型返回的字符串是undefined var box=true; alert(ty ...

  8. Spring配置文件解析--bean属性

    1.bean设置别名,多个别名用逗号隔开 <!--使用alias--> <bean id="app:dataSource" class="...&quo ...

  9. ASP.NET服务器控件数据绑定总结

    using System; using System.Collections.Generic; using System.Text; using System.Web.UI.WebControls;/ ...

  10. Struts、JSTL标签库的基本使用方法

    一 使用Struts标签之前需要经过下面3个步骤的配置. 1.导入TLD文件. 2.在web.xml中注册标签库. 3.在页面中引入标签库. 下面详细介绍以上步骤. 1 导入TLD文件. TLD文件是 ...