views:

605

answers:

1

Hi,

In my app I have added the new Gesture Recognizers that are available in the 3.2 SDK. Everything appears to be working correctly and the response time on the screen been very fast. But for some reason when I add "requireGestureRecognizerToFail" to some of my gestures, there is a very visible delay when the gesture is triggered. Below is a snippet of the code that I use to create the Gesture Recognizers. Does anyone know why there is a delay and how I can fix it? I'm using "requireGestureRecognizerToFail" to prevent the SingleTap gesture from triggering when the user performs a DoubleTap.

Thanks in Advance!

 - (void)createGestureRecognizers {

 //Single Finger Double-Tap
 UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc]
            initWithTarget:self action:@selector(handleSingleDoubleTap:)];
    singleFingerDTap.numberOfTapsRequired = 2;
    [super addGestureRecognizer:singleFingerDTap];

 //Single Finger Tap
 UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc]
              initWithTarget:self action:@selector(handleSingleTap:)];
    singleFingerTap.numberOfTapsRequired = 1;
 [singleFingerTap  requireGestureRecognizerToFail:singleFingerDTap];
 [self addGestureRecognizer:singleFingerTap];

 //Two Finger Pan
 UIPanGestureRecognizer *panGesture2 = [[UIPanGestureRecognizer alloc]
            initWithTarget:self action:@selector(handlePanGesture2:)];
    panGesture2.maximumNumberOfTouches = 2;
 [super addGestureRecognizer:panGesture2];

 //Single Finger Pan
 UIPanGestureRecognizer *panGesture1 = [[UIPanGestureRecognizer alloc]
             initWithTarget:self action:@selector(handlePanGesture1:)];
    panGesture1.maximumNumberOfTouches = 1;
 [panGesture1 requireGestureRecognizerToFail:panGesture2];
 [super addGestureRecognizer:panGesture1];

 [singleFingerDTap release];
 [singleFingerTap release];
    [panGesture1 release];
 [panGesture2 release];
}
+1  A: 

If you want to distinguish between a single and double tap, you must wait long enough to figure out that no second tap is coming before you can call it a single tap. The alternative would be to design all your single tap actions in such a way that they can asynchronously be canceled or reverted when a double tap is detected.

For example, if you have a single tap change pages and a double tap zoom, then you would have to animate a page changing on single tap, then reverse the animation and zoom instead when a second tap is detected. By then the view that handled the single tap may have moved. In most cases, that is more trouble and confusion then it is worth.

drawnonward
Now that I think about what you said, it makes perfect sense that there is a delay. Since I need a more realtime response, I'll have to go back to handling the Touch events on my own. Thanks!
Maddoxx