Search code examples
swifttouchesbegangmsmapview

touchesBegan function never being entered


I'm trying to pop up a popover for my app. So far, the popover pops up at a fixed coordinate, I'm trying to get it to pop at the point where the user tapped. This is what I have:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    print("touchesbegan")
    for touch in touches{
        //Handle touch
        let location = touch.locationInView(self.view)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)

        let vc = storyboard.instantiateViewControllerWithIdentifier("ColonyPopoverController") as! ColonyPopoverController
        vc.modalPresentationStyle = .Popover
        vc.preferredContentSize = CGSizeMake(200, 150)

        if let popoverController = vc.popoverPresentationController {
            popoverController.delegate = self
            popoverController.sourceRect = CGRectMake(location.x, location.y, 20, 10)
            popoverController.sourceView = self.view
            self.presentViewController(vc, animated: true, completion: nil)
        }
    }
}

I notice that the print statement never prints when I tap on the simulator.

I have interaction and multi-touch enabled in my view. I know that that works fine because I also have it integrated with Google Maps, so that when I tap, a google pin appears:

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
    print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude)
    marker.title = "Sydney"
    marker.snippet = "Australia"
    marker.map = mapView

}

and I see the print statements printing as well. Not sure what I'm missing here.

User interaction is enabled for both the superview and the view:

enter image description here

enter image description here


Solution

  • Turns out Googlemaps' GMSView consumes other gestures in view and it has to be explicitly disallowed:

    mapView.settings.consumesGesturesInView = false;