Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with UITapGestureRecognizer for double tap

I've two UITapGestureRecognizer: singleTap and doubleTap initialized with two different actions.

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[singleTap requireGestureRecognizerToFail:doubleTap];
[doubleTap setNumberOfTapsRequired:2];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:singleTap];

When I run my app in simulator the single tap responds correctly but not the double tap ! When I double clicks nothings happens, I suppose iOS dose recognize the double tap because the action of single tap doesn't being called (due to [singleTap requireGestureRecognizerToFail:doubleTap];), but I can't understand why doesn't it do the action handleDoubleTap.

like image 934
Cathylun Avatar asked May 10 '11 14:05

Cathylun


1 Answers

I think the problem is that UIImageView and UILabel both override the default value of YES for the userInteractionEnabled property, and sets it to NO.

Add imageView.userInteractionEnabled = YES; and try again.

like image 71
PeyloW Avatar answered Oct 13 '22 01:10

PeyloW