Setting direction for UISwipeGestureRecognizer

Seems like there is a bug. You can specify the allowed direction(s) as you did. But when you try to access the actual direction that triggered the swipe in the action selector method you still get the bit mask you originally set (for the allowed directions).

This means that checks for the actual direction will always fail when more than 1 direction is allowed.
You can see it for yourself quite easily when you output the value of ‘direction’ in the selector method (ie -(void)scrollViewSwiped:(UISwipeGestureRecognizer *)recognizer).

Filed a bug report (#8276386) to Apple.

[Update] I got an answer from Apple saying that the behavior works as was intended.

So for example in a table view you can swipe left or right in a table view cell to trigger ‘delete’ (this would have directions of the swipe gesture set to left and right)

This means that the original workaround is the way it’s supposed to be used. The direction property can only be used to get the gestures recognized correctly, but not in the method performed on a successful recognition to compare for the actual direction that triggered the recognition.

Leave a Comment