Heuristic
Heuristic

Reputation: 5341

Pan and Tap gesture recognizer for same view, which need to fail for the other?

I need to detect Pan and Tap on the same view, but the tap action is also the first action for pan, so I assume the Tap action need the Pan action to be failed, but then does it make any delay as it has to wait a little bit in order to know if a tap is followed by a movement for a Pan?

Thanks

Upvotes: 5

Views: 10357

Answers (3)

Kamaldeep singh Bhatia
Kamaldeep singh Bhatia

Reputation: 732

I know it's old question but if someone got this in search so they can try this

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, 
         shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
   // Don't recognize a pan gesture until a tap fails.
   if gestureRecognizer == self.panGesture && 
          otherGestureRecognizer == self.tapGesture {
      return true
   }
   return false
}

So what exactly happening. We have got request for Pan and need to check if this is Tap or not. So here it will check and say to PanGesture that it should wait before reacting for TapGesture to get fail. Same you can do for other overlapping Gestures.

For more info refer Preferring One Gesture Over Another

Upvotes: 6

Pushpak Narasimhan
Pushpak Narasimhan

Reputation: 454

There won't be a conflict unless you do this.

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

Upvotes: 2

XJones
XJones

Reputation: 21967

the tap action is not the first action for a pan. the tap happens after touch up (e.g. the user lifts their finger). the pan happens while the touch is still down (e.g. the finger is pressing on the screen and starts to move).

try it, it will work fine.

Upvotes: 11

Related Questions