响应者链
2016-09-05 本文已影响20人
Kevin_wzx
1.简单认识
1.事件的传递大多是都依赖于响应者链。响应者链是一系列响应者对象的关系集。它始于第一响应者而终于Application对象。如果第一响应者不能处理这个事件,它会将事件传递给响应者链中得下一个响应者。
2.第一响应者
2.1第一响应者是一个可以响应并处理事件的对象。UIResponder就是所以响应者对象的基类,它定义了一些通用的接口并不仅仅只是事件的处理还有普遍的响应者行为。UIApplication,UIcontroller,和UIview类的实例都是响应者,这就意味所有的view和大多数关键的controller对象都是响应者。值得注意的是核心动画图层Core Animation layers不是响应者。(看看它们都是继承谁就就知道啦)
2.2.第一响应者条件

3.响应者链使用情况

4. 响应者链图析




5.实例分析







6.更多资料
http://smnh.me/hit-testing-in-ios/
7. 注意点
例子:控制器中添加一个表格视图,然后表格视图上有UITextFile控件,点击以后展开键盘;点屏幕触发- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法收起键盘;但是在表格视图中这个方法失效,原因是:这个方法是在View上面,而该控件添加再表格上,所以根本没有触发该方法。