开发者

Very hard to capture double tap on UIButton subclass. (time delay to capture double tap)

Im talking about two separate touches on the screen with the same finger

I think i have the coding right for this. but it is almost impossible for me to actually generate a double tap on my iPad. Is it possible to increase the time interval between a single and double tap, so it is easier to trigger. I do a double tap very fast and it captures it as two single clicks. only sometimes am i lucky enough to trigger a double tap. I place my subclass of UIButton item into a scrollview.

Anyway my subclass of UIButton implements:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{

 UITouch *touch = [[event allTouches] anyObject];

 NSLog(@"Touch count:%d",touch.tapCount);

 开发者_如何学Cif (touch.tapCount == 1) 
 {
  //Do things for one touch
 }
 else if (touch.tapCount == 2) 
 {
  //Do things for double touch
 }
}

This is capturing the event. and that is why i think my code is right, i just couldnt find anything that has to do with UIEvent and what determines how many touches happen. I tested this same thing in a different UIView and it worked exactly as expected.


Your code is detecting two fingers in the view at the same time, not a rapid sequence of on finger (double tap).

If you want to detect a double tap, the easiest way is to use a Gesture Recoginizer. Wherever do setup of your sublass, add this code:

UITapGestureRecognizer *singleFingerDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerDoubleTap:)];
singleFingerDoubleTap.numberOfTouchesRequired = 1;
singleFingerDoubleTap.numberOfTapsRequired = 2;
[self addGestureRecognizer:singleFingerDTap];
[singleFingerDTap release];

And implement a method to hande the double tap:

-(void)handleSingleFingerDoubleTap:(id)sender {
  //Do stuff
}


you not calling [super touchesBegan:touches withEvent:event]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜