iOS 事件传递与视图响应链

84 阅读1分钟

事件传递 UIAppication

UIWindow

hitTest:withEvent:

pointInside:withEvent:

subviews 倒序遍历

sub hitTest:withEvent:

  • (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { NSLog(@"最终哪个视图响应返回哪个"); return self; }
  • (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { NSLog(@"点击是否在视图方位内"); return YES; }

视图响应

UIView继承UIResponder

  • (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  • (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  • (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event