热门标签 | 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。这样做将允许您调整罗盘和“合法”标签,以适应在地图上的自定义视图。


推荐阅读
  • 在真实开发中,因为需求是不断变化的,说不定什么时候就需要往模型里添加新的字段,添加新的模型,甚至是大规模的重构; ... [详细]
  • Android 常用工具类源码大全
    Android常用工具类源码大全 ... [详细]
  • L18 如何快速查找文档获得帮助
    原地址:http:www.howzhi.comcourse286lesson2121查找文档快速苹果提供了丰富的文档,以帮助您成功构建和部署你的应用程序, ... [详细]
  • 添加#import头文件倒入mapkit.framework库mapkit.framework是属于ui,可以在故事版上添加mkmap ... [详细]
  • 高德IOS真机调试LMAMapKit出错问题的解决方法(directory not found for option)
    1最近项目到了收尾阶段,所以开始了在真机部署调试,之前的模拟器环境下测试项目,一切都没问题,今天真机调试过程中, ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • Oracle10g备份导入的方法及注意事项
    本文介绍了使用Oracle10g进行备份导入的方法及相关注意事项,同时还介绍了2019年独角兽企业重金招聘Python工程师的标准。内容包括导出exp命令、删用户、创建数据库、授权等操作,以及导入imp命令的使用。详细介绍了导入时的参数设置,如full、ignore、buffer、commit、feedback等。转载来源于https://my.oschina.net/u/1767754/blog/377593。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • macOS Big Sur全新设计大版本更新,10+个值得关注的新功能
    本文介绍了Apple发布的新一代操作系统macOS Big Sur,该系统采用全新的界面设计,包括图标、应用界面、程序坞和菜单栏等方面的变化。新系统还增加了通知中心、桌面小组件、强化的Safari浏览器以及隐私保护等多项功能。文章指出,macOS Big Sur的设计与iPadOS越来越接近,结合了去年iPadOS对鼠标的完善等功能。 ... [详细]
  • 本文介绍了如何使用MATLAB调用摄像头进行人脸检测和识别。首先需要安装扩展工具,并下载安装OS Generic Video Interface。然后使用MATLAB的机器视觉工具箱中的VJ算法进行人脸检测,可以直接调用CascadeObjectDetector函数进行检测。同时还介绍了如何调用摄像头进行人脸识别,并对每一帧图像进行识别。最后,给出了一些相关的参考资料和实例。 ... [详细]
  • Apple iPad:过渡设备还是平板电脑?
    I’vebeenagonizingoverwhethertopostaniPadarticle.Applecertainlydon’tneedmorepublicityandthe ... [详细]
  • iOS 系统架构 && 常用 framework
    整理自互联网,感谢原文作者!1.iOS基于UNIX系统,因此从系统的稳定性上来说它要比其他操作系统的产品好很多2.iOS的系统架构分为四层,由上到下一次为:可触摸层(CocoaTo ... [详细]
  • 在iOS6之后,不再使用谷歌地图了,而是使用苹果自己的地图,但是API编程接口没有太大的变化。开发人员不需要再学习很多新东西就能开发地图应用,这是负责任的做法。因此本节介绍的内容也同样适用于iOS5 ... [详细]
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社区 版权所有