MKMapView tell map to show MKAnnotations with padding?

Viewed 961

So I am using this call:

mapView.showAnnotations(annotations, animated: true)

to animate the app to show the annotations. That works great. What I need on top of that, is to tell the Map to add 100 pixels of padding to the left of the region that it normally zooms to when I call:

mapView.showAnnotations(annotations, animated: true)

I have a view over the map on the left side of the screen and I don't want the annotations appear under, so, I want to add padding to the left of them so they're not hidden by the view.

I tried the MKMapView calls "setRegion" and:

mapView.setVisibleMapRect(mapRect, edgePadding: UIEdgeInsetsMake(20, 100, 20, 20), animated: true)

but, it's not really working especially when I try to combine the:

mapView.showAnnotations(annotations, animated: true)

and:

mapView.setVisibleMapRect(mapRect, edgePadding: UIEdgeInsetsMake(20, 100, 20, 20), animated: true)

What is the correct way to achieve this?

1 Answers
Related