i need to detect direction of my swipe gesture and i\'ve got problem with it. gesture is working, but i don\'t know how to detect direction. ...
swipeGe
Extending omz's solution:
self.myView is the view I want to put the gesture recognizer on. The code below is not tested, I guess it would be better to keep the recognizers as propertys and add them inside viewDidLoad() or xib file. self is a UIViewController.
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft ];
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedRight:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight ];
[self.view addGestureRecognizer:swipeRight];
Add those two methods to your UIViewController and add necessary actions:
- (IBAction)swipedRight:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"swiped right");
}
- (IBAction)swipedLeft:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"swiped left");
}