Double-tap or two single-taps?

前端 未结 6 1786
轮回少年
轮回少年 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:09

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
        UITouch *touch = [touches anyObject];
    
        NSUInteger tapCount = [touch tapCount];
    
        switch (tapCount) {
            case 1:
                [self performSelector:@selector(singleTapMethod) withObject:nil afterDelay:.4];
                break;
            case 2:
                [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod) object:nil];
                [self performSelector:@selector(doubleTapMethod) withObject:nil afterDelay:.4];
                break;
            case 3:
                [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doubleTapMethod) object:nil];
                [self performSelector:@selector(tripleTapMethod) withObject:nil afterDelay:.4];
                break;
            case 4:
                [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(tripleTapMethod) object:nil];
                [self quadrupleTap];
                break;
            default:
                break;
        }
    
    }
    @end
    

    for me this code is working prefectly fine.... :) the last post was around august 15 09.... but i was going through the same problem so thought to share the solution i found....

提交回复
热议问题