1. UILongPressGestureRecognizer(长按)基本介绍
- 父类是UIGestureRecognizer
- 一般开发中,长按操作只会做一次
- 假设在一开始长按的时候就做一次操作
- 默认调用两次
2. UILongPressGestureRecognizer应用举例
- (void)setUpLongPress
{
// 长按
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.imageView addGestureRecognizer:longPress];
}
// 长按图片的时候就会触发长按手势
- (void)longPress:(UILongPressGestureRecognizer *)longPress
{
// 一般开发中,长按操作只会做一次
// 假设在一开始长按的时候就做一次操作
if (longPress.state == UIGestureRecognizerStateBegan) {
NSLog(@"%ld",longPress.state);
}
}
3. UILongPressGestureRecognizer属性
// 要求的点击次数,默认为0次
@property (nonatomic) NSUInteger numberOfTapsRequired; // Default is 0.
// 要求的手指数量,默认为1个
@property (nonatomic) NSUInteger numberOfTouchesRequired __TVOS_PROHIBITED;
// 最小的按压持续时间,默认是0.5秒
@property (nonatomic) CFTimeInterval minimumPressDuration;
// 允许识别过程中手指移动的最大距离,默认是10
@property (nonatomic) CGFloat allowableMovement; // Default is 10. Maximum movement in pixels allowed before the gesture fails. Once recognized (after minimumPressDuration) there is no limit on finger movement for the remainder of the touch tracking