我使用两个不同的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"执行选择器。错误在哪里?
答案 0 :(得分: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];
最好的问候;)
答案 1 :(得分:1)
我想你可能已经省略了:
[doubleTapGR setDelegate:self];
答案 2 :(得分:0)
我发现我真的很傻:)
我写道:
[doubleTapGR setNumberOfTouchesRequired:2];
而不是:
[doubleTapGR setNumberOfTapsRequired:2];
随意删除此答案。对不起StackOverflow。