0

我在单击和双击中为 UIImageView 添加了 UITapGestureRecognizer。单击方法 A 将调用,双击方法 B 将调用。

它仅第一次完美运行。

第一次

如果我单击 UIImageView,方法 A 会按预期调用。

如果我双击 UIImageView,方法 B 会按预期调用。

第二次

如果我单击 UIImageView,方法 A 会按预期调用。

如果我在 UIImageView 上双击,则不再调用方法 B 仅调用方法 A。我不知道我在哪里制造问题。

    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideHandle:)];
[gestureRecognizer setDelegate:self];
[userResizableView addGestureRecognizer:gestureRecognizer];
[gestureRecognizer release];

UITapGestureRecognizer *gestureRecognizer1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
gestureRecognizer1.numberOfTapsRequired = 2;

[gestureRecognizer1 setDelegate:self];
[userResizableView addGestureRecognizer:gestureRecognizer1];
[gestureRecognizer1 release];

[gestureRecognizer requireGestureRecognizerToFail:gestureRecognizer1];
4

1 回答 1

-1

我已经测试了你的代码,它运行良好!

您在释放gestureRecognizer1 后添加requireGestureRecognizerToFail。这不应该是一个问题,因为我在关注评论并编辑了这个答案后进行了测试,但试一试。也给变量和方法一些有意义的名字。

    UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
                            initWithTarget:self action:@selector(handleDoubleTap:)];
    doubleTapGestureRecognizer.numberOfTapsRequired = 2;
    [userResizableView addGestureRecognizer:doubleTapGestureRecognizer];

    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
                            initWithTarget:self action:@selector(handleSingleTap:)];
    singleTapGestureRecognizer.numberOfTapsRequired = 1;
    [singleTapGestureRecognizer requireGestureRecognizerToFail: doubleTapGestureRecognizer];
    [userResizableView addGestureRecognizer:singleTapGestureRecognizer];

    [doubleTapGestureRecognizer release];
    [singleTapGestureRecognizer release];
于 2012-09-20T14:58:46.393 回答