添加长按手势如下,执行的时候会发现响应两次
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”);
}
}

本文介绍了一个关于UILongPressGestureRecognizer在iOS应用中响应两次的问题及其解决方案。通过调整手势识别器的状态判断,确保了长按操作只触发一次。
1092

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



