andrew_machen andrew_machen - 2 months ago 20
Swift Question

MKMapView and AutoLayout issue

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:
enter image description here

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:
enter image description here

I am using the latest version of Xcode 8 available from the App Store.


This bug has been fixed in Xcode 8.1


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.

enter image description here

I request you to raise this as bug @