我希望能够检测到两倍,也可以在手指触摸该层时检测到。这并非完全单击,因为要发生点击,手指必须触摸并离开屏幕。我想检测一个或多个手指触摸视图的确切时间。

这是我的代码:

    doubleTap = [[UITapGestureRecognizer alloc]
                  initWithTarget:self
                  action:@selector(handleDoubleTap:)];
    [doubleTap setCancelsTouchesInView:NO];
    [doubleTap setNumberOfTapsRequired:2];
    [doubleTap setDelegate:self];
    [self.view addGestureRecognizer:doubleTap];


    singleTap = [[UITapGestureRecognizer alloc]
                 initWithTarget:self
                 action:@selector(handleSingleTap:)];
    [singleTap setCancelsTouchesInView:NO];
    [singleTap setNumberOfTapsRequired:1];
    [singleTap setNumberOfTouchesRequired:1];
    [singleTap requireGestureRecognizerToFail: doubleTap];
    [singleTap setDelegate:self];
    [self.view addGestureRecognizer:singleTap];

这就是我处理单键水龙头的方式
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {

    if(recognizer.state == UIGestureRecognizerStateBegan) {
        [self doSomething];
    }
}

该代码仅在手指离开时触发handleSingleTap方法,因此状态始终为UIGestureRecognizerStateEnd。

我现在如何触发一个或多个手指触摸视图但手指仍在那呢?

谢谢。

最佳答案

使用带有minimumPressDuration = 0.001的长按手势识别器。

07-26 09:38