MKMapView 不加载地图并显示黄色背景
MKMapView doesn't load map and show yellow background
一旦我启动该应用程序,它就会加载您所在城市的地图。它在 IOS 9-10 期间运行良好。自从 iOS 11 地图开始出现异常行为。现在,当您启动应用程序时,它会显示黄色地图。如果我点击主页按钮,等待 3-5 秒,然后返回到应用程序,它会像它应该的那样显示地图......试图调试它,改变布局结构,没有任何帮助......下面你可以看到当你打开应用程序第一次和 5 秒后返回主屏幕。
像这样添加到视图中:
mapView.isScrollEnabled = false
mapView.isZoomEnabled = false
mapView.isPitchEnabled = false
mapView.isRotateEnabled = false
mapContainer.addSubview(mapView)
mapView.fillSuperview()
然后在检测到位置后设置地图,如下所示:
let center = CLLocationCoordinate2D(latitude: mapLatitude - 0.004, longitude: mapLongitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.04, longitudeDelta: 0.04))
self.mapView.setRegion(region, animated: true)
所以错误是错误的初始化。当我应该在 viewDidLoad 中进行初始化时,我确实在 viewController 的顶部初始化了 mapview。这解决了问题。
一旦我启动该应用程序,它就会加载您所在城市的地图。它在 IOS 9-10 期间运行良好。自从 iOS 11 地图开始出现异常行为。现在,当您启动应用程序时,它会显示黄色地图。如果我点击主页按钮,等待 3-5 秒,然后返回到应用程序,它会像它应该的那样显示地图......试图调试它,改变布局结构,没有任何帮助......下面你可以看到当你打开应用程序第一次和 5 秒后返回主屏幕。
像这样添加到视图中:
mapView.isScrollEnabled = false
mapView.isZoomEnabled = false
mapView.isPitchEnabled = false
mapView.isRotateEnabled = false
mapContainer.addSubview(mapView)
mapView.fillSuperview()
然后在检测到位置后设置地图,如下所示:
let center = CLLocationCoordinate2D(latitude: mapLatitude - 0.004, longitude: mapLongitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.04, longitudeDelta: 0.04))
self.mapView.setRegion(region, animated: true)
所以错误是错误的初始化。当我应该在 viewDidLoad 中进行初始化时,我确实在 viewController 的顶部初始化了 mapview。这解决了问题。