Tanguy A.
Tanguy A.

Reputation: 155

Pan gesture won't forward touch to Mapbox MGLMapView

I am trying to achieve something very basic with a MGLMapView from Mapbox iOS SDK. I render a MGLMapView with scroll enabled so one can move the view on pan gesture; I would like to detect if the view has been moved so I attached a pan gesture recognizer to this view.

Please note that I am using the interface builder to do so, as you can see on the screenshot below.

interface builder screenshot

I linked the gesture recognizer to an IBAction which is indeed triggered anytime one tries to move the view on the map. However, the view is not moved, i.e. the touch event is not forwarded to the MGLMapView anymore. Of course I unchecked the option 'Cancel touches in view' of my pan gesture recoginzer. Just to be sure I also linked the pan gesture recognizer to an IBOublet in my code so I can set its member cancelsTouchesInView to false but it does not change anything.

I tried to add a tap gesture recognizer (2 touches) in a similar way and it works fine, i.e. associated IBAction is triggered and touch is forwarded to the map view (map view is zoomed in on double tap).

What did I miss here with the pan gesture recognizer?

Thanks a lot for your help.

Upvotes: 2

Views: 656

Answers (1)

Tanguy A.
Tanguy A.

Reputation: 155

So I used a different approach to achieve what I wanted to: rather than attaching a new pan gesture recognizer to the map view, I attach a new target to the existing pan gesture recognizer.

for gestureRecognizer in self.mapView.gestureRecognizers! {
    if let _ = gestureRecognizer as? UIPanGestureRecognizer {
        gestureRecognizer.addTarget(self, action: #selector(self.panOnMap))
        break
    }
}

Then both default panning and my method panOnMap are called.

I am still not fully satisfied of this solution since it looks more like a hack. Furthermore I noticed that they are two pan gesture recognisers attached to the map view, and I am not sure which one I should target.

Upvotes: 3

Related Questions