转自: http://blog.csdn.net/guoyuyanmen/article/details/50463764
添加长按手势如下,执行的时候会发现响应两次
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTapAction:)];
longPress.minimumPressDuration = 0.8; //定义按的时间
longPress.numberOfTouchesRequired = 1;
[self addGestureRecognizer:longPress]; 解决办法:
- (void) longTapAction:(UILongPressGestureRecognizer *)longPress {
if (longPress.state == UIGestureRecognizerStateBegan) {
NSLog(@”long pressTap state :begin”);
}else {
NSLog(@”long pressTap state :end”);
}
}
本文介绍了一种解决iOS应用中长按手势被触发两次的问题的方法。通过设置UILongPressGestureRecognizer的参数,并在响应方法中检查手势状态,确保了手势只被正确响应一次。

1万+

被折叠的 条评论
为什么被折叠?



