I would like to use a Map Kit View has a subview of a View Controller that occupies only a portion of the screen, rather than as a fullscreen view.
I am unsure if the following is a bug that I should report, or if I am missing some vital knowledge on how to use Map Kit Views. The easiest way to explain the issue is through pictures.
In the first screenshot I have setup two subviews, a UIImageView and a MKMapView, on an otherwise blank View Controller using Interface Builder. Both subviews have been constrained in the same way, i.e. height, width, constrained to the top or bottom of their superview, and horizontally in the container. Xcode give no errors.
Screenshot before issue:
The second screenshot is after I restart Xcode. The UIImageView is the same, however the MKMapView has increased its width and height to 1,000. Xcode gives the following error: Height and vertical position are ambiguous for "Map View". Updating the frames does not restore the correct layout. To fix the issue, the MKMapView needs to be manually resized to fit into the ViewController, after which updating the frames restores the layout to that shown in the first screenshot. Restarting Xcode causes the issue to repeat.
Screenshot after restarting Xcode:
I am using the latest version of Xcode 8 available from the App Store.
Update:
This bug has been fixed in Xcode 8.1
Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views. For example, you can constrain a button so that it is horizontally centered with an Image view and so that the button's top edge always remains 8 points below the image's bottom.
Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.
This seems a bug and for workaround you can add a simple UIView instead of MKMapKit and after adding the constraints change the class of the view from UIView
to MKMapView
. Although you won't be able to set the properties of this map view from storyboard but you can set it in the code using it's outlet.
I request you to raise this as bug @https://bugreporter.apple.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With