事件类型.png
(1)手指按下事件
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
(2)手指移动事件
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
(3)手指抬起事件
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
(4)意外中断事件(如电话打扰)
- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
(5)3D触摸事件
- (void)touchesEstimatedPropertiesUpdated:(NSSet * _Nonnull)touches
(1)开始加速
- (void)motionBegan:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event;
(2)结束加速
- (void)motionEnded:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event;
(3)加速中断
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event;
- (void)remoteControlReceivedWithEvent:(nullable UIEvent *)event;
存放在NSSet中,无序且不能重复,通过anyObject来访问单个元素。,通过forin循环来遍历NSSet中的每一个元素 当用户用一根手指触摸屏幕时,会创建一个与手指相关联的UITouch对象, 保存着跟本次手指触摸相关的信息,比如触摸的位置、时间、阶段, 当手指离开屏幕时,系统会销毁相应的UITouch对象
(1)获取触摸产生时所处的窗口
@property(nonatomic,readonly,retain) UIWindow *window;
(2)获取触摸产生时所处的视图
@property(nonatomic,readonly,retain) UIView *view;
(3)获取短时间内点按屏幕的次数,可以根据tapCount判断单击、双击或更多的点击
@property(nonatomic,readonly) NSUInteger tapCount;
(4)获取触摸事件产生或变化时的时间,单位是秒
@property(nonatomic,readonly) NSTimeInterval timestamp;
(5)获取当前触摸事件所处的状态 触摸事件在屏幕上有一个周期,即触摸开始、触摸点移动、触摸结束,还有中途取消。而通过phase可以查看当前触摸事件在一个周期中所处的状态
@property(nonatomic,readonly) UITouchPhase phase;
UITouchPhase 枚举: UITouchPhaseBegan 开始触摸 UITouchPhaseMoved 移动 UITouchPhaseStationary 停留 UITouchPhaseEnded 触摸结束 UITouchPhaseCancelled 触摸中断
(6)触摸类型
@property(nonatomic,readonly) UITouchType type;
UITouchType 枚举: UITouchTypeDirect 垂直的触摸类型 UITouchTypeIndirect 非垂直的触摸类型 UITouchTypeStylus 水平的触摸类型
(7)获取手指与屏幕的接触半径
@property(nonatomic,readonly) CGFloat majorRadius;
获取手指与屏幕的接触半径的误差
@property(nonatomic,readonly) CGFloat majorRadiusTolerance;
(8)获取触摸手势
@property(nullable,nonatomic,readonly,copy) NSArray <UIGestureRecognizer *> *gestureRecognizers;
(9)获取触摸压力值,一般的压力感应值为1.0
@property(nonatomic,readonly) CGFloat force;
(10)获取最大触摸压力值
@property(nonatomic,readonly) CGFloat maximumPossibleForce;
(1)返回当前触摸点在view上的位置 这里返回的位置是针对view的坐标系的(以view的左上角为原点(0, 0)),调用时传入的view参数为nil的话,返回的是触摸点在UIWindow的位置
- (CGPoint)locationInView:(nullable UIView *)view;
(2)返回前一个触摸点的位置
- (CGPoint)previousLocationInView:(nullable UIView *)view;
(3)当前触摸对象的坐标
- (CGPoint)preciseLocationInView:(nullable UIView *)view;
(4)当前触摸对象的前置坐标
- (CGPoint)precisePreviousLocationInView:(nullable UIView *)view;
UIEvent:称为事件对象,记录事件产生的时刻和类型,事件对象中包含与当前多点触摸序列相对应的所有触摸对象,还可以提供与特定视图或窗口相关联的触摸对象。
(1)获取事件类型
@property(nonatomic,readonly) UIEventType type;
UIEventType枚举: UIEventTypeTouches 触摸事件 UIEventTypeMotion 加速事件 UIEventTypeRemoteControl 远程控制事件 UIEventTypePresses 按压事件
(2)获取远程控制事件
@property(nonatomic,readonly) UIEventSubtype subtype;
UIEventSubtype 枚举:
// 不包含任何子事件类型
UIEventSubtypeNone = 0,
// 摇晃事件(从iOS3.0开始支持此事件)
UIEventSubtypeMotionShake = 1,
//远程控制子事件类型(从iOS4.0开始支持远程控制事件)
//播放事件【操作:停止状态下,按耳机线控中间按钮一下】
UIEventSubtypeRemoteControlPlay = 100,
//暂停事件
UIEventSubtypeRemoteControlPause = 101,
//停止事件
UIEventSubtypeRemoteControlStop = 102,
//播放或暂停切换【操作:播放或暂停状态下,按耳机线控中间按钮一下】
UIEventSubtypeRemoteControlTogglePlayPause = 103,
//下一曲【操作:按耳机线控中间按钮两下】
UIEventSubtypeRemoteControlNextTrack = 104,
//上一曲【操作:按耳机线控中间按钮三下】
UIEventSubtypeRemoteControlPreviousTrack = 105,
//快退开始【操作:按耳机线控中间按钮三下不要松开】
UIEventSubtypeRemoteControlBeginSeekingBackward = 106,
//快退停止【操作:按耳机线控中间按钮三下到了快退的位置松开】
UIEventSubtypeRemoteControlEndSeekingBackward = 107,
//快进开始【操作:按耳机线控中间按钮两下不要松开】
UIEventSubtypeRemoteControlBeginSeekingForward = 108,
//快进停止【操作:按耳机线控中间按钮两下到了快进的位置松开】
UIEventSubtypeRemoteControlEndSeekingForward = 109,
(3)获取触摸产生或变化的时间戳
@property(nonatomic,readonly) NSTimeInterval timestamp;
(1)获取触摸点的集合,可以判断多点触摸事件
- (nullable NSSet <UITouch *> *)allTouches;
(2)获取指定窗口里的触摸点
- (nullable NSSet <UITouch *> *)touchesForWindow:(UIWindow *)window;
(3)获取指定视图里的触摸点
- (nullable NSSet <UITouch *> *)touchesForView:(UIView *)view;
(4)获取手势对象
- (nullable NSSet <UITouch *> *)touchesForGestureRecognizer:(UIGestureRecognizer *)gesture;