Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Update:
This bug has been fixed in Xcode 8.1

like image 458
andrew_machen Avatar asked Oct 20 '16 15:10

andrew_machen


People also ask

What is the use of Autolayout?

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.

What is Autolayout in Swift?

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.


1 Answers

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 @https://bugreporter.apple.com

like image 200
Inder Kumar Rathore Avatar answered Nov 15 '22 19:11

Inder Kumar Rathore