简体   繁体   中英

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

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

try it, it will work fine.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM