美文网首页
iOS事件的传递链和响应链

iOS事件的传递链和响应链

作者: 如日之升101 | 来源:发表于2019-04-28 17:56 被阅读0次

彻底理解事件的传递链和响应链需要先弄明白iOS对象为什么可以响应用户交互,理解UIResponder类;

1.1响应者对象(UIResponder)

iOS中不是所有的对象都能够处理触摸事件,只有继承了UIResponder类的时间才能够响应事件,以下类都是继承自UIResponder的,所以都能够响应事件:

  • UIApplication
  • UIViewController
  • UIView
    大家有没有思考过为什么继承了UIResponder的类就能够响应就能够接收并响应事件呢?通过分析我们可以得出结论,UIResponder类提供了以下方法用来响应用户事件:
    UIResponder内部提供了以下方法来处理事件事件
---- 触摸事件(讲解重点)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
---- 加速计事件
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event;
---- 远程控制事件
- (void)remoteControlReceivedWithEvent:(UIEvent *)event;

未完待续

相关文章

网友评论

      本文标题:iOS事件的传递链和响应链

      本文链接:https://www.haomeiwen.com/subject/gftjnqtx.html