0

I have the following code which creates four gestures:

    self.userInteractionEnabled = YES;

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

UILongPressGestureRecognizer * longPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
longPressGesture.minimumPressDuration = 0.00;
[self addGestureRecognizer:longPressGesture];

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];

The Pan and LongPress work fine, but I never get either of the Swipe gestures. Is there something special I need to do to have the swipe selectors get called?

Thanks

LilMoke
  • 3,176
  • 7
  • 48
  • 88

1 Answers1

1

I just answered this yesterday.

Short form: a swipe gesture is a special case of a pan gesture, and by default no two gestures will recognize simultaneously. Look into gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: and/or requireGestureRecognizerToFail:. You'll find further help for this and related issues in Apple's guide.

Community
  • 1
  • 1
rickster
  • 124,678
  • 26
  • 272
  • 326
  • LOL, yes you did. I did read through the doc, and I see the problem, although I could not find confirmation. If you notice my code above, I set the LongTap minimumPressDuration to 0.00. When I do this and I set a breakpoint at both gestures, Pan and Swipe, it only breaks on Pan. However, if I sent the minimumPressDuration to 0.125, 1/4 sec. it breaks at both. I could not find anything that explained this so I am at a loos as to why the pressDuration matters. But, yes, your solution works for the most part. – LilMoke Mar 29 '12 at 10:12