先了解下UIView与CALayer的关系
- UIView为CALayer提供内容,负责处理触摸事件,参与响应链 ,内部的backgroundColor是对CALayer内部的backgroundColor的包装
- CALayer显示内容contents,contents通过backing store显示出来,可以理解为显示出来的是bit位图
关于事件传递的两个方法
//返回事件响应的view
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
//判断点击位置是否在视图范围内
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
事件的传递的流程,自下而上
hitTest: withEvent:系统内部实现
事件响应的流程,自上而下
视图的响应事件
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;