1

我正在使用两种不同的 TapGestureRecognizer 来处理屏幕上的单击和双击。这是代码:

UITapGestureRecognizer *tapGR =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
    [tapGR setDelegate:self];
    [tapGR setNumberOfTapsRequired:1];
    [self addGestureRecognizer:tapGR];


    UITapGestureRecognizer *doubleTapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
    [doubleTapGR setNumberOfTouchesRequired:2];
    [self addGestureRecognizer:doubleTapGR];

    [tapGR requireGestureRecognizerToFail : doubleTapGR];

    [tapGR release];
    [doubleTapGR release];

即使我指定了 [tapGR requireGestureRecognizerToFail: doubleTapGR],也会执行“handleTap”选择器。错误在哪里?

4

3 回答 3

5

你犯了一个错误!您使用setNumberOfTouchesRequired了方法doubleTapGR而不是使用setNumberOfTapsRequired. 这是更正后的代码:

UITapGestureRecognizer *tapGR =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
[tapGR setDelegate:self];
[tapGR setNumberOfTapsRequired:1];
[self addGestureRecognizer:tapGR];


UITapGestureRecognizer *doubleTapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTapGR setNumberOfTapsRequired:2];
[self addGestureRecognizer:doubleTapGR];

[tapGR requireGestureRecognizerToFail : doubleTapGR];

[tapGR release];
[doubleTapGR release];

最好的祝福 ;)

于 2012-06-18T16:00:42.587 回答
1

我想你可能遗漏了:

[doubleTapGR setDelegate:self];
于 2012-06-18T15:52:25.063 回答
0

我发现我真的很笨:)

我写:

[doubleTapGR setNumberOfTouchesRequired:2];

代替:

[doubleTapGR setNumberOfTapsRequired:2];

随意删除此答案。对不起 StackOverflow。

于 2012-06-18T15:52:52.000 回答