Sobes.tech
Junior — Middle

Which has a greater importance: highPriorityGesture or simultaneousGesture?

sobes.tech AI

Answer from AI

In iOS, when handling gestures, the importance weight depends on the context and the delegate settings of UIGestureRecognizer. Usually, if two gestures are recognized simultaneously, the highPriorityGesture takes precedence over simultaneousGesture if the first has a higher priority set or if the delegate implements the method gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer:.

That is, highPriorityGesture can block the execution of simultaneousGesture if explicitly specified in the handling logic. Without explicit settings, both gestures can be recognized simultaneously.

Example:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    if gestureRecognizer == simultaneousGesture && otherGestureRecognizer == highPriorityGesture {
        return true // makes simultaneousGesture wait for highPriorityGesture
    }
    return false
}

Thus, highPriorityGesture usually has a greater weight if explicitly set in the delegate.