热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MKMapView忽略iOS11和iPhoneX上的安全区域-MKMapViewignoringSafeAreaoniOS11andiPhoneX

ImtryingtomigrateaapptoiOS11andfordaysImstuckwithoneuglyUIbugaftertheother.T

I'm trying to migrate a app to iOS 11 and for days I'm stuck with one ugly UI bug after the other. This time: MKMapView. I have a bunch of buttons which I pinned to the Safe Area Layout Guides and everything is working fine - except the MKMapView.

我正在尝试将一个应用程序迁移到ios11上,几天来,我一直被一个丑陋的UI bug困扰着。这一次:MKMapView。我有一堆按钮,我把它们固定在安全区域布局指南上,一切都运行良好——除了MKMapView。

It completely ignores the Safe Area and therefore the compass and legal buttons are hidden under bars or my own UI elements. To verify, I created a new project with only one plain UIViewController. Then I added a MKMapView and configured custom "additionalSafeAreaInsets" which are indeed completely ignored.

它完全忽略了安全区,因此指南针和合法按钮被隐藏在条形或我自己的UI元素下。为了验证,我创建了一个只有一个纯UIViewController的新项目。然后我添加了一个MKMapView并配置了自定义的“additionalsafearesets”,实际上完全忽略了它。

The worse is probably that even with just the MKMapView, the legal label looks horribly wrong on iPhone X.

更糟糕的是,即使只使用MKMapView,法律标签在iPhone X上看起来也非常错误。

Question: is there any way I can inset the legal label and the compass to not get hidden by custom views?

问:有什么方法可以让我的合法标签和指南针不被自定义视图隐藏?

enter image description here

3 个解决方案

#1


1  

The only solution worked for me

唯一的解决办法是我。

  1. Disable compass in the MapView
  2. 在MapView中禁用指南针
  3. Create a new Compass button manually and simply put it wherever you like it
  4. 手动创建一个新的指南针按钮,只要把它放在你喜欢的任何地方

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)
    }
}

#2


0  

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

警告:目前- ios11.2.5 - MKMapView有严重的错误,所以,它是随机的,大部分是成功的或讽刺的。

Since iOS11 use swift:

因为iOS11使用迅速:

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

Older versions (8-10):

旧版本(8 - 10):

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

#3


0  

The correct approach is to set additionalSafeAreaInsets of the view controller that contains the MKMapView. Doing so will allow you to adjust both the compass and "Legal" label as needed to accommodate for custom views on top of the map.

正确的方法是设置包含MKMapView的视图控制器的additionalSafeAreaInsets。这样做将允许您调整罗盘和“合法”标签,以适应在地图上的自定义视图。


推荐阅读
author-avatar
小晴天9927
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有