首页 > 解决方案 > 如何在呈现 UIViewController 之前预加载 MKMapView?

问题描述

我以模态方式呈现 a UIViewController,其中包含 a MKMapView。但UIViewController仅应在MKMapView完成加载/渲染特定区域后呈现。所以如果UIViewController出现了,地图应该已经在那里了。我需要加载它以便在这些UIViewController. 当然,我UIActivityIndicatorView向用户展示了一个。

我已经做了什么:

let mapViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "mapView") as! MapViewViewController
let _ = mapViewController.view //viewDidLoad gets called and views are loaded

mapViewController.set(region: Region)
self.mapInfoCard.loadingIndicator.startAnimating()

//called on MKMapView´s mapViewDidFinishLoadingMap(_ mapView: MKMapView) delegate function
mapViewController.finishedHandler = {
   self.mapInfoCard.loadingIndicator.stopAnimating()
   self.present(mapViewController, animated: true, completion: nil)
}

但从mapViewDidFinishLoadingMap(_ mapView: MKMapView)未被调用。委托函数在mapView(_ mapView: MKMapView, regionWillChangeAnimated animated: Bool)我设置区域后被调用,但mapViewWillStartLoadingMap(_ mapView: MKMapView)mapViewDidFinishLoadingMap(_ mapView: MKMapView)从不调用。只有当我呈现的UIViewController时候,不等死finishedHandler

标签: iosswiftmapkitmkmapview

解决方案


推荐阅读