Get swipe direction in Cocoa Touch Get swipe direction in Cocoa Touch xcode xcode

Get swipe direction in Cocoa Touch


You're not using the UISwipeGestureRecognizercorrectly. Its direction is always going to be what you've set it to (in this case UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft, or 3).

If you want to capture swipes left and right that you can differentiate between, you'll have to set up a separate recognizer for each. Apple does this in their SimpleGestureRecognizers sample.


What you have to do is just change the codes for adding gesture recognizer.

UISwipeGestureRecognizer *leftRecognizer;leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];[leftRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft];[[self view] addGestureRecognizer:leftRecognizer];[leftRecognizer release];UISwipeGestureRecognizer *rightRecognizer;rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];[rightRecognizer setDirection: UISwipeGestureRecognizerDirectionRight];[[self view] addGestureRecognizer:rightRecognizer];[rightRecognizer release];