I'm working on a simple note-taking/painting app. I have a view controller that works like a paper/canvas. In it I want to implement UISwipeGestureRecognizer, for example, when the user quickly wants to show the menu he or she can swipe upwards instead of hitting my "edit" button, or maybe swipe left or right when he/she wants to change paper/note.
The problem is, when the user swipes (with two fingers) the app also draws a short line in the same direction.
I have implemented the UISwipeGestureRecognizer like this:
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
recognizer.numberOfTouchesRequired = 2;
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
// Delegate method
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return YES;
}
// Helper method for handeling swipes
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionUp) {
[self enableEditingMode];
}
}
The painting mechanism is handled in the same controller's following methods:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
It seems like the three methods above gets called before my UIGestureRecognizer. I have tried to make a BOOL variable, and disable the painting code if the boolean variable is YES. But this didn't work. Any other ideas on how to solve this problem would be great!
Note: I'm doing the swipe testing in the simulator. Maybe that effects it?