一、初始化手势
1、- initWithTarget:action:
(1) 方法原型
- (instancetype)initWithTarget:(id)target
action:(SEL)action
//给手势绑定一个事件
二、手势添加或移除绑定事件
1、- addTarget:action:
(1) 方法原型
- (void)addTarget:(id)target
action:(SEL)action
//添加绑定事件
2、- removeTarget:action:
(1) 方法原型
- (void)removeTarget:(id)target
action:(SEL)action
//移除绑定事件
三、获取手势点击的次数和点击位置
1、- locationInView:
(1) 方法原型
- (CGPoint)locationInView:(UIView *)view
//获取手势在视图上点击的位置坐标
2、- locationOfTouch:inView:
(1) 方法原型
- (CGPoint)locationOfTouch:(NSUInteger)touchIndex
inView:(UIView *)view
//获取手势每次点击对应的位置坐标
3、- numberOfTouches
(1) 方法原型
- (NSUInteger)numberOfTouches
//获取手势点击次数
四、获取手势的状态和点击的视图
1、state
(1) 方法原型
@property(nonatomic, readonly) UIGestureRecognizerState state
(2) 状态类型
typedef enum {
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
} UIGestureRecognizerState;
Possible: 识别器在未识别出它的手势,但可能会接收到触摸时处于这个状态。这是默认状态。
Began: 识别器接收到触摸并识别出是它的手势时处于这个状态。响应方法将在下个循环步骤中被调用。
Changed:the recognizer has received touches recognized as a change to the gesture. 识别器识别出一个变化为它的手势的触摸,响应方法将在下个循环步骤中被调用。
Ended:识别器在识别到作为当前手势结束信号的触摸时处于这个状态。响应方法将在下个循环步骤中被调用 并且 识别器将重置为possible状态。
Cancelled:识别器处于取消状态.响应方法将在下个循环步骤中被调用 并且 识别器将重置为possible状态。
Failed: 识别器接收到不能识别为它的手势的一系列触摸。响应方法不会被调用并且识别器将重置为possible状态。
Recognized: 识别器已识别到它的手势。响应方法将在下个循环步骤中被调用并且识别器将重置为possible状态。
2、enabled
(1) 方法原型
@property(nonatomic, getter=isEnabled) BOOL enabled
//手势是否可用
五、取消或者延迟点击
1、cancelsTouchesInView
(1) 方法原型
@property(nonatomic) BOOL cancelsTouchesInView
//取消点击
2、delaysTouchesBegan
(1) 方法原型
@property(nonatomic) BOOL delaysTouchesBegan
//延迟点击的开始状态
3、delaysTouchesEnded
@property(nonatomic) BOOL delaysTouchesEnded
//延迟点击的结束状态
六、指定手势识别器来之间的依赖关系
1、- requireGestureRecognizerToFail:
(1) 方法原型
- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer
七、设置手势的委托
1、delegate
(1) 方法原型
@property(nonatomic, weak) id< UIGestureRecognizerDelegate > delegate
八、有关手势操作的方法
1、- touchesBegan:withEvent:
(1) 方法原型
- (void)touchesBegan:(NSSet<UITouch *> *)touches
withEvent:(UIEvent *)event
//触摸开始
2、- touchesMoved:withEvent:
(1) 方法原型
- (void)touchesMoved:(NSSet<UITouch *> *)touches
withEvent:(UIEvent *)event
//触摸移动
3、- touchesEnded:withEvent:
(1) 方法原型
- (void)touchesEnded:(NSSet<UITouch *> *)touches
withEvent:(UIEvent *)event
//触摸结束
4、- touchesCancelled:withEvent:
(1) 方法原型
- (void)touchesCancelled:(NSSet<UITouch *> *)touches
withEvent:(UIEvent *)event
//触摸取消
5、- reset
(1) 方法原型
- (void)reset
//重置手势
6、- ignoreTouch:forEvent:
(1) 方法原型
- (void)ignoreTouch:(UITouch *)touch
forEvent:(UIEvent *)event
//忽略手势
7、- canBePreventedByGestureRecognizer:
(1) 方法原型
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
8、- canPreventGestureRecognizer:
(1) 方法原型
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
9、- shouldRequireFailureOfGestureRecognizer:
(1) 方法原型
- (BOOL)shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
10、- shouldBeRequiredToFailByGestureRecognizer:
(1) 方法原型
- (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
11、- ignorePress:forEvent:
(1) 方法原型
- (void)ignorePress:(UIPress *)button
forEvent:(UIPressesEvent *)event
12、- pressesBegan:withEvent:
(1) 方法原型
- (void)pressesBegan:(NSSet<UIPress *> *)presses
withEvent:(UIPressesEvent *)event
13、- pressesChanged:withEvent:
(1) 方法原型
- (void)pressesChanged:(NSSet<UIPress *> *)presses
withEvent:(UIPressesEvent *)event
14、- pressesEnded:withEvent:
(1) 方法原型
- (void)pressesEnded:(NSSet<UIPress *> *)presses
withEvent:(UIPressesEvent *)event
15、- pressesCancelled:withEvent:
(1) 方法原型
- (void)pressesCancelled:(NSSet<UIPress *> *)presses
withEvent:(UIPressesEvent *)event
八、识别不同的手势
1、allowedPressTypes
(1) 方法原型
@property(nonatomic, copy) NSArray <NSNumber *> *allowedPressTypes
2、allowedTouchTypes
(1) 方法原型
@property(nonatomic, copy) NSArray <NSNumber *> *allowedTouchTypes
九、状态类型
1、UIGestureRecognizerState
typedef enum {
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
} UIGestureRecognizerState;