ios - MKMapView 的比例尺未显示

标签 ios swift mkmapview

我正在做一个 iOS 应用程序。在 Xcode 9.1 中,我通过

创建了一个 MKMapView
let mapView = MKMapView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height))
mapView.isUserInteractionEnabled = false
mapView.mapType = .satellite
mapView.showsCompass = false
mapView.showsScale = true
view.addSubview(mapView)

但是当我在模拟器中运行它时,比例没有显示,我在日志中收到了三条消息:

Could not inset compass from edges 9

Could not inset scale from edge 9

Could not inset legal attribution from corner 4

指南针未显示(如预期),但如果我将 mapView.showsCompass 更改为 true 也不会显示。但是,会显示法律链接。我在这里错过了什么?我猜这与 iOS 11 引入的新安全区域有关,但我看不出这对于我想要覆盖整个屏幕的 View 有多重要。

最佳答案

在 iOS 10 或更低版本中

正如@Paulw11 所说,默认情况下仅在缩放时显示比例。

在 iOS 11 中

您可以使用 scaleVisibilityhttps://developer.apple.com/documentation/mapkit/mkscaleview/2890254-scalevisibility

let scale = MKScaleView(mapView: mapView)
scale.scaleVisibility = .visible // always visible
view.addSubview(scale)

关于ios - MKMapView 的比例尺未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47272663/

相关文章:

ios - 如何为 MKPolygonRenderer 提供图像?

ios - UIView.animation 不动画颜色变化

ios - 在 PageViewController 的两侧禁用滑动/滚动

swift - 在 Swift 中制定隐私政策 : How to make UIAlertController action button disabled until message is scrolled to the bottom

ios - 单击 TableView 某个部分中的任意位置后如何执行 segue?

ios - Swift:没有标签栏的屏幕截图

ios - 在 Swift 应用程序中将自定义 .dylib 放在哪里?

ios - 如何清空整个核心数据表?

ios - map View 的 'shows user location'选项有什么作用?

ios - 正向地理编码可以在模拟器上运行,但不能在 iPhone 上运行