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];
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.