iOS 事件传递及响应过程

iOS 事件传递及响应过程

—->>事件到来——>>事件分发 ——>>事件响应


事件( Events)

官方文档( Events(iOS)) 是这样描述的:
Users manipulate their iOS devices in a number of ways, such as touching the screen or shaking the device. iOS interprets when and how a user is manipulating the hardware and passes this information to your app. The more your app responds to actions in natural and intuitive ways, the more compelling the experience is for the user.
1.触摸事件( Touch Events) (单点事件、多点触摸及各种手势)
2.晃动时间(Motion Events) (重力、加速度等传感器)
3.远程控制事件(Remote-Control Events)(线控耳机、AirPlay 等)


事件分发( Event Delivery)

触摸事件:触摸->硬件中断-> UIKit 封装成 UIEvent对象->当前运行的应用程序的事件队列 - >UIApplication 对象 - >key window - >Hit - Testing VIew
其他事件:key window - > First Responder
目的:
The ultimate goal of these event paths is to find an object that can handle and respond to an event. Therefore, UIKit first sends the event to the object that is best suited to handle the event. For touch events, that object is the hit-test view, and for other events, that object is the first responder.
方法:
- Hit-Testing Returns the View Where a touch Occurred (Touch)
The hit-test view is given the first opportunity to handle a touch event. If the hit-test view cannot handle an event, the event travels up that view’s chain of responders as described in “ The Responder Chain Is Made Up of Responder Objects ” until the system finds an object that can handle it.
- The Responder Chain Is Made Up of Responder Objects (Motion Or R-C)


事件响应

这里写图片描述
这里写图片描述

注意:
hitTest:withEvent: 方法将会忽略( hidden = YES) 的视图
禁止用户操作( userInteractionEnabled = NO) 的视图
以及 alpha 级别 小于0.01 (alpha < 0.01) 的视图
如果一个子视图的区域超过父视图的 bound 区域(父视图的 clips ToBounds 属性为 NO, 这样超过父视图 bound 区域的视图的内容也会显示),那么正常情况下对子视图在父视图之外区域的触摸操作不会被父视图识别,因为父视图的 pointInSide:withEvent:方法会返回 NO, 这样子就不会继续向下便利子视图了.当然也可以重写pointInSide:withEvent:方法 来处理这种情况.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值