我正在做一个 iOS 应用程序。在 Xcode 9.1 中,我通过
创建了一个 MKMapViewlet 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 中
您可以使用 scaleVisibility
。
https://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/