Double-tap or two single-taps?

前端 未结 6 1856
轮回少年
轮回少年 2021-02-02 17:46

What is the time limit for two taps to be considered a double-tap, on the iPhone OS?

// Edit: Why is this important?

In order to handle single-tap and double-tap

6条回答
  •  半阙折子戏
    2021-02-02 18:04

    You can detect any number of tap by the tap gesture. No need of playing with NSTouches either. For all the user seeking for the solution here it is.

    These simple lines of code does the duty of single and double tap functionality.

      UITapGestureRecognizer *doubleTapRecg = [[UITapGestureRecognizer alloc]
                                                 initWithTarget:self 
                                                 action:@selector(doubleTapped:)];
        doubleTapRecg.delegate = self;
        doubleTapRecg.numberOfTapsRequired = 2;
        doubleTapRecg.numberOfTouchesRequired = 1;
        [view addGestureRecognizer:doubleTapRecg];
    
    
        UITapGestureRecognizer *tapRecg = [[UITapGestureRecognizer alloc]
                                           initWithTarget:self 
                                           action:@selector(tapped:)];
        tapRecg.delegate = self;
        tapRecg.numberOfTapsRequired = 1;
        tapRecg.numberOfTouchesRequired = 1;
        [view addGestureRecognizer:tapRecg];
        [tapRecg requireGestureRecognizerToFail:doubleTapRecg];
    
    
        [doubleTapRecg release];
        [tapRecg release];
    

提交回复
热议问题