UIEvent基本介绍:父类是NSObject--每产生一个事件,就会产生一个UIEvent对象,UIEvent:称为事件对象,记录事件产生的时刻和类型
@class UIWindow, UIView, UIGestureRecognizer, UITouch;
UIEvent事件类型
typedef NS_ENUM(NSInteger, UIEventType) {
UIEventTypeTouches,//触摸事件
UIEventTypeMotion,//加速计事件
UIEventTypeRemoteControl,//远程控制
UIEventTypePresses API_AVAILABLE(ios(9.0)),//按压事件
};
//子事件类型
typedef NS_ENUM(NSInteger, UIEventSubtype) {
// available in iPhone OS 3.0
//事件没有子类型 iOS3.0之后可以用
UIEventSubtypeNone = 0,
// for UIEventTypeMotion, available in iPhone OS 3.0
//抖动
UIEventSubtypeMotionShake = 1,
// for UIEventTypeRemoteControl, available in iOS 4.0
//遥控的事件子类型 iOS4.0之后可以用
UIEventSubtypeRemoteControlPlay = 100,//播放
UIEventSubtypeRemoteControlPause = 101,//暂停
UIEventSubtypeRemoteControlStop = 102,//停止
UIEventSubtypeRemoteControlTogglePlayPause = 103,//播放和暂停之间切换【操作:播放或暂停状态下,按耳机线控中间按钮一下】
//track -- 跟踪
UIEventSubtypeRemoteControlNextTrack = 104,//下一曲【操作:按耳机线控中间按钮两下】
UIEventSubtypeRemoteControlPreviousTrack = 105,//上一曲【操作:按耳机线控中间按钮三下】
//Backward -- 向后 Seeking --寻求
UIEventSubtypeRemoteControlBeginSeekingBackward = 106,//快退开始【操作:按耳机线控中间按钮三下不要松开】
UIEventSubtypeRemoteControlEndSeekingBackward = 107,//快退结束【操作:按耳机线控中间按钮三下到了快退的位置松开】
//forward -- 向前
UIEventSubtypeRemoteControlBeginSeekingForward = 108,//快进开始【操作:按耳机线控中间按钮两下不要松开】
UIEventSubtypeRemoteControlEndSeekingForward = 109,//快进结束【操作:按耳机线控中间按钮两下到了快进的位置松开】
};
相关API
UIKIT_EXTERN API_AVAILABLE(ios(2.0)) @interface UIEvent : NSObject
@property(nonatomic,readonly) UIEventType type API_AVAILABLE(ios(3.0));//事件类型
@property(nonatomic,readonly) UIEventSubtype subtype API_AVAILABLE(ios(3.0));//子事件类型
@property(nonatomic,readonly) NSTimeInterval timestamp;//事件发生时间
//返回与接收器相关联的所有触摸对象。
@property(nonatomic, readonly, nullable) NSSet <UITouch *> *allTouches;
//返回属于一个给定窗口的接收器的事件响应的触摸对象。
- (nullable NSSet <UITouch *> *)touchesForWindow:(UIWindow *)window;
//返回属于一个给定视图的触摸对象,用于表示由接收器所表示的事件。
- (nullable NSSet <UITouch *> *)touchesForView:(UIView *)view;
//返回触摸对象被传递到特殊手势识别
- (nullable NSSet <UITouch *> *)touchesForGestureRecognizer:(UIGestureRecognizer *)gesture API_AVAILABLE(ios(3.2));
// An array of auxiliary UITouch’s for the touch events that did not get delivered for a given main touch. This also includes an auxiliary version of the main touch itself.
//会将丢失的触摸放到一个新的 UIEvent 数组中,你可以用 coalescedTouchesForTouch(_:) 方法来访问 coalesced -- 合并
- (nullable NSArray <UITouch *> *)coalescedTouchesForTouch:(UITouch *)touch API_AVAILABLE(ios(9.0));
// An array of auxiliary UITouch’s for touch events that are predicted to occur for a given main touch. These predictions may not exactly match the real behavior of the touch as it moves, so they should be interpreted as an estimate.
//predicted -- 预料到的
////辅助UITouch的触摸,预测发生了一系列主要的触摸事件。这些预测可能不完全匹配的触摸的真正的行为,因为它的移动,所以他们应该被解释为一个估计。
- (nullable NSArray <UITouch *> *)predictedTouchesForTouch:(UITouch *)touch API_AVAILABLE(ios(9.0));
网友评论