MKMapView ignores safe zone on iOS 11 and iPhone X

I am trying to port an application to iOS 11, and for several days I got stuck with one ugly UI error after another. This time: MKMapView. I have a bunch of buttons that I attached to the Safe Area guides, and everything works fine - except for MKMapView.

It completely ignores the safe zone, and therefore the compass and legal buttons are hidden in bars or my own user interface elements. To check, I created a new project with one simple UIViewController. Then I added MKMapView and set up custom "extra SafeAreaInsets" that are really completely ignored.

The worst part is that even with MKMapView, the legal shortcut looks terribly wrong on the iPhone X.

Question : is there a way so that I can insert the legal label and compass so that it is not hidden by user views?

enter image description here

+7
source share
4 answers

The correct approach is to install additionalSafeAreaInsets view controller that contains MKMapView . This will allow you to configure both the compass and the Legal label if necessary to place custom views on top of the map.

+1
source

Only solution for me

  1. Disable compass in MapView
  2. Create a new Compass button manually and just place it where you like it.

Here is an example

  @IBOutlet weak var mapView: MKMapView! { didSet { let userTrackingButton = MKUserTrackingButton(mapView: mapView) userTrackingButton.layer.position = CGPoint(x: 100, y: 100) userTrackingButton.backgroundColor = UIColor.white let compassButton = MKCompassButton(mapView: mapView) compassButton.layer.position = CGPoint(x: 100, y: 150) compassButton.compassVisibility = .adaptive mapView.delegate = self mapView.showsUserLocation = true mapView.setUserTrackingMode(.follow, animated: true) mapView.addSubview(userTrackingButton) mapView.addSubview(compassButton) } } 
+1
source

WARNING: at the moment - iOS 11.2.5 - MKMapView is badly buggy, so it works randomly, mostly successfully or sarcastically.

Since iOS11 uses fast:

 self.mapView.directionalLayoutMargins = NSDirectionalEdgeInsets(top: 70, leading: 10, bottom: 10, trailing: 48) 

Old versions (8-10):

 [self.mapView setLayoutMargins:UIEdgeInsetsMake(70, 10, 48, 10)]; 
0
source

Looking at this for one of my own projects, it looks like the builder interface has a solution for this:

On the map view, select "Preserve Superview Margins" and "Safe area relative Margins"

On the map screen, select "Keep Surveillance Fields" and "Safe Area of ​​Relative Fields", and the legal + compass will be correctly installed.

0
source

Source: https://habr.com/ru/post/1273608/


All Articles