Does anyone know of a way to change the placing of the compass in MKMapview?
I'm talking about the compass that shows up in the upper right corner of the map when it's rotated.
I'm making it so you can see the map blurred underneath the navigation bar, which means the frame's y origin will be underneath the nav-bar. The problem is that when the map is rotated, it automatically adds the compass button in the upper right corner and as you can (kind of) see in the screenshot below, that's covered by the navBar.
I haven't seen any documentation talking about the the compass, anybody have any ideas?
With iOS 8 you can simple do:
My tests have shown, that the
MKMapView
somehow knows in what context it is displayed. If you use a regularUINavigationController
you'll get the compass positioned below the navigation bar even when it is translucent.There is a new
UIViewController
property in iOS 7 that defines the beginning of the actual content on the Y axis. It is calledtopLayoutGuide
.Sadly you cannot really influence the value that Apple uses to calculate this property in different contents. It also depends on the visibility of the status bar.
BUT: To solve this problem, I created a simple custom object that I return in my custom view controller:
Then I overrode the following two methods in my
UIViewController
subclass:This insets the layout guides by 44 points. And the
MKMapView
will use these values to position the compass at the top, and the "Legal" label at the bottom.One thing that you now have to pay attention to is, that you cannot use the layout guides anymore within the auto layout visual format language.
Swift:
Where instead of 20 you could calculate your UI elements height to have a more dynamic solution adjusting to each device or element.