1. UIEvent基本介绍
- 父类是NSObject
- 每产生一个事件,就会产生一个UIEvent对象
- UIEvent:称为事件对象,记录事件产生的时刻和类型
2. UIEvent事件类型
UIEventType-事件类型 |
含义 |
IOS启用版本 |
UIEventTypeTouches |
触摸 |
|
UIEventTypeMotion |
加速计 |
|
UIEventTypeRemoteControl |
远程控制 |
|
UIEventTypePresses |
按压 |
9.0 |
UIEventSubtype-事件子类型 |
含义 |
对应事件 |
IOS启用版本 |
UIEventSubtypeNone |
空类型 |
|
3.0 |
-- |
-- |
-- |
-- |
UIEventSubtypeMotionShake |
摇动 |
UIEventTypeMotion |
3.0 |
-- |
-- |
-- |
-- |
UIEventSubtypeRemoteControlPlay |
播放 |
UIEventTypeRemoteControl |
4.0 |
UIEventSubtypeRemoteControlPause |
暂停 |
同上 |
4.0 |
UIEventSubtypeRemoteControlStop |
停止 |
同上 |
4.0 |
UIEventSubtypeRemoteControlTogglePlayPause |
|
同上 |
4.0 |
UIEventSubtypeRemoteControlNextTrack |
|
同上 |
4.0 |
UIEventSubtypeRemoteControlPreviousTrack |
|
同上 |
4.0 |
UIEventSubtypeRemoteControlBeginSeekingBackward |
|
同上 |
4.0 |
UIEventSubtypeRemoteControlEndSeekingBackward |
|
同上 |
4.0 |
UIEventSubtypeRemoteControlBeginSeekingForward |
|
同上 |
4.0 |
UIEventSubtypeRemoteControlEndSeekingForward |
|
同上 |
4.0 |
3. 常见属性
事件类型
@property(nonatomic,readonly) UIEventType type;
@property(nonatomic,readonly) UIEventSubtype subtype;//事件子类型
事件产生的时间
@property(nonatomic,readonly) NSTimeInterval timestamp;//时间戳
4. 常见方法
- UIEvent还提供了相应的方法可以获得在某个view上面的触摸对象(UITouch)
// 获取touch
- (nullable NSSet <UITouch *> *)allTouches;
- (nullable NSSet <UITouch *> *)touchesForWindow:(UIWindow *)window;
- (nullable NSSet <UITouch *> *)touchesForView:(UIView *)view;
- (nullable NSSet <UITouch *> *)touchesForGestureRecognizer:(UIGestureRecognizer *)gesture NS_AVAILABLE_IOS(3_2);
// 获取touch数组
// 一组辅助UITouch用于触摸事件,而这些事件没有被交付给给定的主触摸。这也包括了主触摸本身的辅助版本。
- (nullable NSArray <UITouch *> *)coalescedTouchesForTouch:(UITouch *)touch NS_AVAILABLE_IOS(9_0);
// 获取预测touch数组
// 一组辅助UITouch的触摸事件,预计会发生在给定的主触点上。这些预测可能与移动的实际行为并不完全匹配,因此它们应该被解释为一种估计。
- (nullable NSArray <UITouch *> *)predictedTouchesForTouch:(UITouch *)touch NS_AVAILABLE_IOS(9_0);