长按手势就是用户在使用一个或者多个手指在屏幕上长按不松开时的一种机制,UILongPressGestureRecognized可以检测到用户的这种操作。
UILongPressGestureRecognizer中定义了一些属性来设置手势处理器的相关信息
minimumPressDuration指定用户至少在屏幕上按下多少秒才会触发该手势,默认值为0.5;
allowableMovement制定该手势允许用户移动的最大距离。如果用户手指按下时移动超出距离,则手势取消
numberOfTouche'sRequired指定必须使用几个手指在屏幕上长按才会发出该手势
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGesture:)];
//设置至少在屏幕上按下多少秒才能发出手势
longPress.minimumPressDuration = 0.5;
//设置长按手势允许用户手指移动的最大距离
longPress.allowableMovement = 1;
//设置必须使用几个手指长按才会触发该手势
longPress.numberOfTouchesRequired = 1;
[chattextLabel addGestureRecognizer:longPress];
</pre></p><pre name="code" class="objc">-(void)longPressGesture:(UILongPressGestureRecognizer *)gesture{ if (gesture.state == UIGestureRecognizerStateBegan){ NSLog(@"触发了手势