0

What is the correct way to allow scrollview to pass gestures to the subviews?

Fdr
  • 3,726
  • 5
  • 27
  • 41
  • I not sure what do you want. For the case your subview has a gesture conflict with its superview(scrollview), `requireGestureRecognizerToFail` helps. – jhd Aug 23 '16 at 11:50

1 Answers1

0

You should add gesture recognizer to ScrollView like this:

        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTap:")
        scrollView.addGestureRecognizer(tapGestureRecognizer)

Then handle the tap like this:

func handleTap(tap: UITapGestureRecognizer)  {

        let location = tap.locationInView(tap.view)

        for i in 0..<scrollView.subviews.count{
            let subViewTapped = scrollView.subviews[i]
            if CGRectContainsPoint(subViewTapped.frame, location) {

        print("tapped subview at index\(i)")
                // do your stuff here

            }
        }

    }
Muzahid
  • 5,072
  • 2
  • 24
  • 42