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

懵懂的女人 提交于 2020-01-24 05:08:06

问题


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


回答1:


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.




回答2:


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




回答3:


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

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


来源:https://stackoverflow.com/questions/15307157/pan-and-tap-gesture-recognizer-for-same-view-which-need-to-fail-for-the-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!