Search code examples
iosswiftannotationsmkmapviewzposition

IOS 11 - MKMapView pin dialog not clickable when another pin is behind


I did notice an issue on IOS 11 when using MKMapView.

When I want to click on the button action from the pin dialog and there is another pin behind the button action, it does not get the gesture.

It should be something about zPosition, but I don't know if there is any way to modify just the zPosition of the dialog (MKAnnotationView.annotation) and put it in front of the pins (MKAnnotationView.image) position.

For IOS version < 11 it does work perfectly.

Is someone having the same trouble?

Thank you!


Solution

  • Finally I've found a solution!

    Here it comes, if someone needs it:

    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        if #available(iOS 11, *) {
            for annotationView in mapView.annotations {
                if mapView.view(for: annotationView) == view {
                        mapView.view(for: annotationView)?.isUserInteractionEnabled = true
                        mapView.view(for: annotationView)?.becomeFirstResponder()
                }
                else{
                    mapView.view(for: annotationView)?.isUserInteractionEnabled = false
                }
            }
        }
    }
    

    All in order now!