I have a MKMapView
that marks a specific region using MKPolygon
. I want the map to have minimum zoom factor that fits inside the mapView / screen, means completely visible.
To achieve this I tried the following
MKPolygon *overlay;
[[self mapView] setVisibleMapRect:[overlay boundingMapRect] edgePadding:UIEdgeInsetsMake(16, 16, 16, 16) animated:YES];
Unfortunately my mapView does not set the whole rect visible. The rect fills the map instead of fitting.
This is what I need vs. what I got:
vs.
How can I achieve my goal?
I finally found the answer. It didn't have to do anything with the MKMapView
. I just started using size classes in Xcode 6 and so there was my problem located.
The call to [MKMapView -setVisibleMapRect:edgePanning:animated:]
was made too early, namely in the -viewDidLoad
method.
When I was thinking of Annas comment and probed a bit I discovered the she was totally right. Then it dawned on me that I should call the mapView method later, e.g. -viewDidLayoutSubviews
.
As I moved the one line it worked just perfectly! Thanks, Anna!