Problem with UITapGestureRecognizer for double tap

Cathylun picture Cathylun · May 10, 2011 · Viewed 9.2k times · Source

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.

Answer

PeyloW picture PeyloW · May 10, 2011

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.