compass, scale, legal attribution

I am placing an MKMapView in a UIViewController.view, which is below a UINavigationController. I am using addSubview and setting constraints. The compass, scale, and legal attribution were positioning fine until iOS 11. If I run it in iOS 11.0.1, 11.0.2, or 11.1, the compass appears behind the navigation bar insted of below it where we can see it. In the debugger, I get the following:


Could not inset compass from edges 9
Could not inset scale from edge 9
Could not inset legal attribution from corner 4


The weird thing is iOS 11.0.3 positioned these controls correctly. So it appears it was fixed briefly and then broken again with 11.1.


Is there something new I should be doing with safeArea, like telling the mapView about safeAreaInsets after I call addSubview()?

Replies

I have narrowed this down. The behaviour only happens when I place MKMapView in the DetailViewController part of the Master-Detail App template. Easy to reproduce:

  1. New "Master-Detail App" project.
  2. In Main.storyboard, add MKMapView to the DetailViewController.
  3. Add constraints to Superview (not Safe Area) for top, bottom, leading, and trailing; constant=0 for all four. There are some problems Xcode 9.1 when doing this. I finally got all four constraints set to zero without complaints but it wasn't easy.
  4. While in Storyboard, open the Assistant Editor and ctrl-drag an outlet from the MKMapView to the DetailViewController class and name the outlet "mapView"
  5. Add "import MapKit" to the top of DetailViewController.swift
  6. Add the following three lines somewhere in DetailViewController.viewDidLoad():
        mapView.mapType = .hybrid
        mapView.showsCompass = true
        mapView.showsScale = true


I like to use "mapType=.hybrid" because it makes it easier to see the translucent behaviour of the navigation bar in the simulator. Build and run in your favorite iPhone simulator (so far for me, this problem only occurs on iPhone).


To run:

  1. Add a dummy record in the Master table and then click it to load a map in the Detail view.
  2. In the map, zoom in and rotate the map (hold alt down to get two fingers in the simulator).
  3. No compass or scale show.


The compass and scale are actually hidden behind the navigation bar. If you rotate the device in the simulator (Command, left or right arrow), you will see the compass partially showing because the navigation bar gets narrow in landscape view.


Am I missing something or does the combination of UISplitViewController and MKMapView need more work with respect to the new Safe Area insets?

This is definitely busted in 11.0.1 and later. Very easy to reproduce. Only fix (for me) was to move the compass view after it was added to map view.

I'm having this issue too...

I am also having this issue…

I had this issue as well, found the answer for mine today, hope this helps you guys as well:

With the simulator open, go to the DEBUG menu on the mac top bar, the last option is location, mine was showing this error when set to NONE. Set it Custom Location, first with you prompt you to a custom location on a new window, fill that, close the simulator, and relaunch the app. It should get the custom location from your code now.

How exactly did you move the compass view?