ios捕获并处理event的过程

1.UIApplication(继承自UIResponder)通过自己的UIWindow的- (void)sendEvent:(UIEvent *)event; // called by UIApplication to dispatch events to views inside the window方法将事件派发出去.
2.UIWindow首先将事件派发给手势识别器(级别高于响应者链),手势识别器不识别(UIGestureRecognizerStateFailed)后派发给window下的视图.
3.派发过程(手势识别失败的情况下)
The UIApplication object calls this method to dispatch events to the window. Window objects dispatch touch events to the view in which the touch occurred, and dispatch other types of events to the most appropriate target object.
这是官方原话,大致理解为派发事件,结合官方文档我个人做以下解释(不服请反驳):UIApplication拿到事件>- (void)sendEvent:(UIEvent *)event; 将事件交给 the touch occurred及触摸的视图,如果触摸的视图通过重写方法不处理该事件则会继续传递到下一个响应者(一般是superview)直到找到响应者,如果没有处理该事件则交由UIApplication最终抛弃。
4.派发过程中会调用- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event; // recursively calls -pointInside:withEvent:. point is in the receiver's coordinate system这是一个抓测试的响应返回一个view及响应者,寻找的过程叫响应者链,通过重写此方法返回一个view拦截响应。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。