Simultaneous gesture recognition for specific gestures Simultaneous gesture recognition for specific gestures swift swift

Simultaneous gesture recognition for specific gestures


Make sure your class implements UIGestureRecognizerDelegate

class YourViewController: UIViewController, UIGestureRecognizerDelegate ...

Set the gesture's delegate to self

yourGesture.delegate = self

Add delegate function to your class

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {    if (gestureRecognizer is UIPanGestureRecognizer || gestureRecognizer is UIRotationGestureRecognizer) {        return true    } else {        return false    }}


any 2 cents for swift 5.1

// suppose You need to prefer pinch to pan:

//UIGestureRecognizerDelegatefunc gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith shouldRecognizeSimultaneouslyWithGestureRecognizer: UIGestureRecognizer) -> Bool {        if gestureRecognizer is UIPinchGestureRecognizer {            return true        }        return false    }