iOS Swift 4: UIView in UIScrollView

565 views Asked by At

I have a UIImageView with a tap gesture recognizer as a subview of a UIScrollView.

A.) If the UIImageView isUserInteractionEnabled=false the scroll view works fine (pinch zoom, scroll) but doesn't recognize the tap gesture on the image.

B.) If isUserInteractionEnabled=true I cannot start pinch zoom or scroll from the image but the tap gesture works.

How can I manage it to work (keep scrolling and zooming but recognize tap on content)?

1

There are 1 answers

2
tphduy On

Because UIScrollView has gestures within for handling scroll, pinch, it means when your UIImageView.isUserInteractionEnabled = true, the UIImageView' tap gesture take those touches and do not forward it to UISCrollView.

Here is the solution by implementing a UIGesture's delegate method: https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/coordinating_multiple_gesture_recognizers/allowing_the_simultaneous_recognition_of_multiple_gestures