I have a method to handle a double swipe gesture I declared elsewhere:
-(void)handleDoubleSwipe:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"double swiped");
if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"swiped left");
}
if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
NSLog(@"swiped right");
}
}
and I declare it elsewhere as:
UISwipeGestureRecognizer *doubleSwipe=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleSwipe:)];
doubleSwipe.numberOfTouchesRequired=2;
doubleSwipe.delegate=self;
doubleSwipe.direction=UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
The problem is that I’m unable to feed the selector with any parameters. It just doesn’t allow me to and autocomplete returns 0 completions. How would I add the doubleSwipe gesture to the parameter for the selector? Right now, the handleDoubleSwipe method does get called and NSLog displays “double swiped” but doesn’t display swiped left or right.
The
directionproperty of the recognizer tells you about the direction(s) the recognizer handles (just as you configured it), not the direction of the actual swipe.You can use the
locationInView:method in combination with thestateproperty to determine where the swipe started and ended.It may be easier though to use one recognizer for each direction.