0

As shown on this picture: Picture I have a GoogleMaps view in the background and a yellow view in the foreground. I need catch tap gestures on the yellow view and every other gestures (mainly pinch) forward to the GoogleMaps view.

I tried to add the yellow view as a child-Subview of the GoogleMaps View (I found this advice here: https://stackoverflow.com/a/10594097/8851253):

class ViewController: UIViewController {
    @IBOutlet weak var mapView: GMSMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let uiView = UIView(frame: CGRect(x: 100, y: 100, width: 150, height: 200))
        uiView.backgroundColor = UIColor.yellow

        // gesture recognizer
        let clickUITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.clickAction(_:)))
        uiView.addGestureRecognizer(clickUITapGestureRecognizer)

        self.mapView.addSubview(uiView)
    }

    @IBAction func clickAction(_ sender: Any) {
        print ("tap")
    }
}

And it would work perfectly if it were normal views, but since it is GMSMapView class, something gets wrong and "clickAction" is not called.

(GMSMapView was assigned to the view in the interface builder)

Here is the project: https://gitlab.com/Cerny/googleMapsForwarding

Any idea how to solve it, please?

Michal
  • 3
  • 4
  • Forwarding gestures **into* a third party library? You probably need to include this more prominently in your question. I was about to suggest looking at delegates but it *obviously* won't be of help. –  Jun 10 '18 at 15:12
  • One thought though - separate comment because I'm clueless about Google Maps. If you are simply trying to *alter* a background view (in this case, a Gllgoel Maps view) via gestures of a view **in front** of it, you could (1) change your view hierarchy and have *both* views - yellow and the map - be controlled and, based on the gesture, adjust the map view. Quite different then "passing the gesture to another view", but possible. –  Jun 10 '18 at 15:15
  • @dfd - Ok I changed the title. I tried to have both views on the same level either and override point(inside:with:) or hitTest(_:with:) and nothing worked. – Michal Jun 10 '18 at 17:04
  • have you tried adding property uiView.isUserInteractionEnabled = true? – Fadielse Jun 20 '18 at 07:11

0 Answers0