1

I have a UIScrollView with several UIViews containing a UIImageView and a UILabel in it. When one of these Images is Single-Tapped, a Box with a individual Text is displayed. But now I also want to implement the possibility to zoom and scroll into the Images (show a UIImageView with the images in a ScrollView, that's not the problem actually). But I need to know, when the picture is Double-Tapped.

I currently use a UITapGestureRecognizer with NumberOfTapsRequires:1 to show the Box with the Texts. But a second UITapGestureRecognizer with required touches of 2 doesn't work, because the first Recognizer is shot before and displays the box over the whole Screen.

Maybe you have a idea, how to realize this. It would be good, if it is a UITapGesture-Solution :)

I've tried it like this now, but it still doesn't work:

UITapGestureRecognizer *gR;
gR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ScrollView_onTap:)];
[gR setNumberOfTapsRequired:1];
[tmpPage addGestureRecognizer:gR];

gR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showFunctionMenu:)];
[gR setNumberOfTapsRequired:2];
[tmpPage addGestureRecognizer:gR];

[gR release];
gR = nil;

The second recognizer is only shot sometimes, but mostly the first. Any ideas?

Kevin Glier
  • 1,346
  • 2
  • 14
  • 30

2 Answers2

4

A solution might be to use the following code fragment, where the requireGestureRecognizerToFail will do the trick for you:

UITapGestureRecognizer *singleTapGR, *doubleTapGR;
singleTapGR = [[UITapGestureRecognizer alloc] initWithTarget:self
    action:@selector(mySingleTapHandler)];
doubleTapGR = [[UITapGestureRecognizer alloc] initWithTarget:self
    action:@selector(myDoubleTapHandler)];
doubleTapGR.numberOfTapsRequired = 2;
[singleTapGR requireGestureRecognizerToFail:doubleTapGR];
[view addGestureRecognizer:singleTapGR];
[view addGestureRecognizer:doubleTapGR];
biegleux
  • 13,179
  • 11
  • 45
  • 52
iOS-Coder
  • 1,221
  • 1
  • 16
  • 28
1

@Kevin I think you want to define the numberOfTapsRequired and not numberOfTouchesRequired both are different things. Check the documentation on the same for more clarity

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UITapGestureRecognizer

Robin
  • 10,011
  • 5
  • 49
  • 75
  • Oh, I actually meant numberOfTapsRequired, corrected it in my Question. But thanks for the link, I really didn't know the difference between the two. – Kevin Glier Apr 14 '11 at 09:44