Bronze Solution Observation


#1

I did the Bronze solution, and then reviewed the 2 existing solutions from TheEskil and JoergK. I noticed that neither of them used the “requireGestureRecognizerToFail” method. From internet searching, I see that one solution (of the ones I could follow!) used that method, and XCode Organizer documentation on that method gives the example of using it to distinguish between single and double taps. So since the 2 other solutions work, is it needed? Well, with a little more debug output, it seems like the answer is “it might in some circumstances”. Without it, a double click invokes the methods tap,and doubleTap. With it, I just see doubleTap. In our example, a single click may select a line, but clears lines in progress, and so is rather innocuous. But there might be applications where we don’t want an extra tap to occur when we do a double tap. Seems like this condition is what requireGestureRecognizerToFail is for.

My code to set up tap recognizers:

// Create instance of a tap gesture recognizer and attach it to TouchDrawView. UITapGestureRecognizer *tapRecognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; [self addGestureRecognizer:tapRecognizer]; // Create instance of a double tap gesture recognizer and attach it to TouchDrawView. UITapGestureRecognizer *tapRecognizerDouble=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDouble:)]; [self addGestureRecognizer:tapRecognizerDouble]; // Make this really function as a double tap recognizer. [tapRecognizerDouble setNumberOfTapsRequired:2]; // Since taps would be seen by the single and double tap recognizers, give the double recognizer precedence. [tapRecognizer requireGestureRecognizerToFail:tapRecognizerDouble];
The double tap handler:

[code]// Pointed to by instantiation of a UITapGestureRecognizer.

  • (void)tapDouble:(UIGestureRecognizer *)gr {
    NSLog(@"%s", func);
    NSLog(@“Recognized a double tap”);
    [self clearAll];
    }
    [/code]

Debug trace without requireGestureRecognizerToFail:

2013-02-09 14:26:51.192 TouchTracker[464:f803] -[TouchDrawView touchesBegan:withEvent:]
2013-02-09 14:26:51.256 TouchTracker[464:f803] -[TouchDrawView tap:]
2013-02-09 14:26:51.256 TouchTracker[464:f803] Recognized a tap
2013-02-09 14:26:51.257 TouchTracker[464:f803] -[TouchDrawView lineAtPoint:]
2013-02-09 14:26:51.260 TouchTracker[464:f803] -[TouchDrawView touchesCancelled:withEvent:]
2013-02-09 14:26:51.261 TouchTracker[464:f803] -[TouchDrawView endTouches:]
2013-02-09 14:26:51.262 TouchTracker[464:f803] -[TouchDrawView drawRect:]
2013-02-09 14:26:51.319 TouchTracker[464:f803] -[TouchDrawView touchesBegan:withEvent:]
2013-02-09 14:26:51.391 TouchTracker[464:f803] -[TouchDrawView tapDouble:]
2013-02-09 14:26:51.392 TouchTracker[464:f803] Recognized a double tap
2013-02-09 14:26:51.393 TouchTracker[464:f803] -[TouchDrawView clearAll]
2013-02-09 14:26:51.393 TouchTracker[464:f803] -[TouchDrawView touchesCancelled:withEvent:]
2013-02-09 14:26:51.394 TouchTracker[464:f803] -[TouchDrawView endTouches:]
2013-02-09 14:26:51.395 TouchTracker[464:f803] -[TouchDrawView drawRect:]