问题
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