iOS手势-UILongPressGestureRecognizer

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容