문제

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.

 - (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];
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top