我希望在UITextView中禁用双击。我已经禁用长按:
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
gestureRecognizer.enabled = NO;
}
[super addGestureRecognizer:gestureRecognizer];
return;
}
我尝试用UITapGestureRecognizer做同样的事情,但它也禁止单击。
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
gestureRecognizer.enabled = NO;
}
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
gestureRecognizer.enabled = NO;
}
[super addGestureRecognizer:gestureRecognizer];
return;
}
如何只禁用双击?
我知道numberOfTapsRequired方法,但不知道如何在我的代码中完全应用它。
答案 0 :(得分:5)
我建议您尝试使用
,而不是禁用点击手势识别器if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
[(UITapGestureRecognizer *)gestureRecognizer setNumberOfTapsRequired:1];
}
通过这种方式,您应该启用单击并禁用双击。
答案 1 :(得分:0)
numberOfTapsRequired的默认值为1,将其设置为2.