How to recognize oneTap/doubleTap at moment?

前端 未结 7 804
独厮守ぢ
独厮守ぢ 2020-12-05 05:51

I Know filtering oneTap/doubleTap using a Apple API. code are follows.

UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
          


        
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 06:54

    This is easiest to do without gesture recognizers. Then you can control the delay. The code below is a variation of Apple's original documentation that I use in one of my projects. I have blog post that talks about it as well.

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
     UITouch *touch = [touches anyObject];
    if (touch.tapCount == 2) {
    //This will cancel the singleTap action
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    }
    
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
     UITouch *touch = [touches anyObject];
    if (touch.tapCount == 1) {
      //if they tapped within the coin then place the single tap action to fire after a delay of 0.3
      if (CGRectContainsPoint(coin.frame,[touch locationInView:self.view])){
        //this is the single tap action being set on a delay
      [self performSelector:@selector(onFlip) withObject:nil afterDelay:0.3];
      }else{
       //I change the background image here
      }
     } else if (touch.tapCount == 2) {
      //this is the double tap action
      [theCoin changeCoin:coin];
     }
    }
    

提交回复
热议问题