Is it possible to have a UIPanGesture and UISwipeGesture together?

I have a UIIMageView subclass and I am adding both a UIPanGestureRecognizer and a UISwipeGestureRecognizer as follows:

self.userInteractionEnabled = YES;

UIPanGestureRecognizer * panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[self addGestureRecognizer:panGesture];

UISwipeGestureRecognizer * swipeUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeUp:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self addGestureRecognizer:swipeUp];

UISwipeGestureRecognizer * swipeDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeDown:)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[self addGestureRecognizer:swipeDown];

but when I swipe up or down my selectors do not get called but the pan always does.

  • Objective C - Iphone. How can I show the numeric keyboard by default?
  • Add AM/PM to datepicker?
  • How to fix “nib but didn't get a UITableView” error?
  • How to select rows while in edit mode?
  • Redirecting Url to app in iphone for linkedIn
  • Storing iPhone application settings in app
  • Any clarification would be helpful.

    Thanks

    Solutions Collect From Internet About “Is it possible to have a UIPanGesture and UISwipeGesture together?”

    The problem is that the swipe gesture will be recognized as a panGesture too.

    What you need to do is set the delegate to a class that implement the method:

    - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
        return YES;
    }
    

    This will allow you to recognize the two gestures simultaneous, but need to be clear to you that always when your swipe is called your pan will called too.

    From apple documentation:

    This method is called when recognition of a gesture by either gestureRecognizer or otherGestureRecognizer would block the other gesture recognizer from recognizing its gesture. Note that returning YES is guaranteed to allow simultaneous recognition; returning NO, on the other hand, is not guaranteed to prevent simultaneous recognition because the other gesture recognizer’s delegate may return YES.