3

我想在 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 方法,但不知道如何在我的代码中准确应用它。

4

2 回答 2

5

我建议您尝试一下,而不是禁用您的点击手势识别器

if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
    [(UITapGestureRecognizer *)gestureRecognizer setNumberOfTapsRequired:1];
}

这样,您应该启用单击并禁用双击。

于 2013-06-30T10:09:21.727 回答
0

numberOfTapsRequired 的默认值为 1,设置为 2。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html

于 2013-06-30T09:17:02.153 回答