Reputation: 3326
I'm working to integrate gestures into a drawing app for the iPad. For example I would like a three finger swipe left to undo a drawing step.
I'm having issues preventing touch data from going to touchesBegan:withEvent: which causes drawing to be made to the screen when performing the gesture.
If I use the delayTouchesBegan property, I can prevent the three finger swipe from delivering this touch data. However, it also delays a drawing when the user is trying to draw a line that goes left. This results in the line starting far away from where the user started drawing.
How can I make sure that my app delays only a three finger swipe and not a single finger swipe?
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
recognizer.numberOfTouchesRequired = 3;
recognizer.direction = UISwipeGestureRecognizerDirectionLeft;
recognizer.delaysTouchesBegan = YES;
[self.view addGestureRecognizer:recognizer];
Upvotes: 0
Views: 860
Reputation: 3326
I found a solution to this issue. Instead of using the delayTouchesBegan property of the gesture recognizer, you can detect the number of touches using the UIEvent passed into the various touch methods. Then just limit the action in the touchBegan:withEvent:, touchesMoved:withEvent:, and touchesEnded:withEvent: methods to perform only when there is a single touch.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//only process touch data if there is a single touch
if ([[event allTouches] count] == 1) {
//draw
}
}
Upvotes: 2
Reputation: 8772
This is a known problem with gestures. There is no way around it, other then opting out of the UISwipeGestureRecognizer and doing the gesture handling manually with touchesBegan/Ended. Then you can set a custom timer with a lower threshold.
Upvotes: 1