理解Mac和iOS中的 Event 处理
根据现在的理解,我把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 处理的更多相关文章
- iOS中多线程原理与runloop介绍
一.线程概述 有些程序是一条直线,起点到终点:有些程序是一个圆,不断循环,直到将它切断.直线的如简单的Hello World,运行打印完,它的生命周期便结束了,像昙花一现那样:圆如操作系统,一直运行直 ...
- IOS中的多线程和NSRunLoop概述(转载)
线程概述 有些程序是一条直线,从起点到终点,如Hello World,运行打印完,它的生命周期便结束了:有些程序是一个圆,不断循环,直到将它切断,如操作系统,一直运行直到你关机. 一个运行着的程序就 ...
- 在Quick-cocos2dx中使用云风pbc解析Protocol Buffers,支持win、mac、ios、android
本例主要介绍 如何将 pbc 集成到quick-cocos2dx框架中,让我们的cocos2dx客户端Lua拥有编解码Protocol Buffers能力. 参考: 云风pbc的用法: http:// ...
- [NodeJs系列][译]理解NodeJs中的Event Loop、Timers以及process.nextTick()
译者注: 为什么要翻译?其实在翻译这篇文章前,笔者有Google了一下中文翻译,看的不是很明白,所以才有自己翻译的打算,当然能力有限,文中或有错漏,欢迎指正. 文末会有几个小问题,大家不妨一起思考一下 ...
- iOS中web app调试(mac)
原文 iOS中web app调试(mac).md 目录 一.真机联调配置 二.mac上Safari配置及真机联调 三.iOS模拟器使用 四.在iOS模拟器中安装app 近期公司vue项目开发,目的是一 ...
- iOS中的堆(heap)和栈(stack)的理解
操作系统iOS 中应用程序使用的计算机内存不是统一分配空间,运行代码使用的空间在三个不同的内存区域,分成三个段:“text segment “,“stack segment ”,“heap segme ...
- iOS中 常用的mac终端指令汇总 技术分享
通常情况下,只有高端用户才会经常用到终端应用.这并不意味着命令行非常难学,有的时候命令行可以轻松.快速的解决问题.相信所有Mac用户都尝试过命令行,今天为大家带来9个非常实用的命令行操作.一些命令行需 ...
- IOS中调用系统的电话、短信、邮件、浏览功能
iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...
- iOS中数据库应用基础
iOS 数据库入门 一.数据库简介 1.什么是数据库? 数据库(Database) 是按照数据结构来组织,存储和管理数据的仓库 数据库可以分为2大种类 关系型数据库(主流) PC端 Oracle My ...
随机推荐
- unity3d magnitude的意义
http://blog.csdn.net/fzhlee/article/details/8663564 magnitude (Read Only) 返回向量的长度,也就是点P(x,y,z)到原点( ...
- CMD和AMD探秘
踏上前端这条道路以来,我一直以为自己就是个娴熟的切图工,每天只需要做着重复的劳动,切图,做网站.然而,技术的发展是日新月异的,切图工早就面临淘汰.随着浏览器功能越来越完善,前端项目越来越大,代码越来越 ...
- ubuntu12.04 安装配置jdk1.7
第一步:下载jdk-7-linux-i586.tar.gz wget -c http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586 ...
- [Hadoop 周边] Hadoop技术生态圈
Hadoop版本演进 当前Hadoop有两大版本:Hadoop 1.0和Hadoop 2.0. Hadoop1.0被称为第一代Hadoop,由分布式文件系统HDFS和分布式计算框架MapReduce组 ...
- HTML5自学笔记[ 4 ]js中新增的选择器方法
querySelector():参数与jQuery一样,这个方法获取一组元素中的第一个元素. querySelectorAll():获取一组元素. getElementsByClassName():获 ...
- 初学java之异常类
//异常类 package st; public class example_1 { public static void main(String args[]) { int n=0,m=0,t=10 ...
- 各种浏览器css hack
转载 http://www.cnblogs.com/jikey/archive/2010/06/21/1761924.html IE都能识别*,标准浏览器(如FF)不能识别*:IE6能识别*,但不能识 ...
- 漫谈iOS Crash收集框架
漫谈iOS Crash收集框架 Crash日志收集 为了能够第一时间发现程序问题,应用程序需要实现自己的崩溃日志收集服务,成熟的开源项目很多,如 KSCrash,plcrashreporter,C ...
- PowerDesigner生成SQL脚本时,对象带有双引号的问题解决
在pdm查看脚本时,发现表名和字段名带有双引号: 1.create table"cfg_user_card_account" ( 2. "user_card_acco ...
- <<薪资至少10K的一道题,你能拿下吗>>练习
偶尔要写写算法,是我平时用来保持感觉的常用的方法.今天看到园子里一面试题,看了一下感觉也能实现,不过过程确实艰的,自认为自己对算法的感觉还不错.不过这题确实我也用了差不多一下午的时间,基本上把工作时间 ...