2

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)?

Chanchal Chauhan
  • 1,530
  • 13
  • 25
  • add the tap gesture to scrollview, if possible – Jen Jose May 25 '18 at 09:00
  • can it help https://developer.apple.com/documentation/uikit/uigesturerecognizerdelegate/1624208-gesturerecognizer?changes=_7 – Alexey Kudlay May 25 '18 at 09:02
  • The scrollview contains a map as an imageView and I have to tap markers on it. So I think the scrollView tap gesture won't help me out. – Dávid Mohácsi May 25 '18 at 09:16
  • try to implement [this](https://developer.apple.com/documentation/uikit/uigesturerecognizerdelegate/1624208-gesturerecognizer?changes=_7) in gesture delegate – Tien Nguyen May 25 '18 at 09:42

1 Answers1

1

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

tphduy
  • 119
  • 7
  • There's no gesture recognizer on the UIimageView (the map) but I cannot set isUserInteractionEnabled=false because it has subviews (also UIImageViews but smaller 'the markers') which has recognizers. The problem is with the map (parent UIImageView) which hasn't got any recognizers. – Dávid Mohácsi May 25 '18 at 12:08
  • Don't worry, just implement method shouldRecognizeSimultaneouslyWith otherGestureRecognizer, don't forget to set your marker'gesture delegate, every gesture in your view controller will work simultaneously. – tphduy May 26 '18 at 04:07