我正在尝试在 IB 的 viewController 中添加一个 mapKit,我将其推到我的导航 Controller 之上,但无论我在循环中的哪个位置添加注释,似乎整个事情都会导致延迟,直到 mapKit 不呈现包含所有内容的 ScrollView 不容易滚动。有没有办法在 iOS 中执行此操作,例如在后台线程中类似于 Android?
下面的代码即使没有添加任何注释,渲染仍然会导致延迟。我很确定还有另一种方法。任何想法?
class DetailViewController: UIViewController , MKMapViewDelegate{
override func viewDidLoad() {
super.viewDidLoad()
self.mapView?.delegate = self
}
//changing the annotation
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if (annotation is MKUserLocation) {
return nil
}
let reuseId = "detailMrker"
var anView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView?.image = UIImage(named:"location.png")
anView?.canShowCallout = true
}
else {
anView?.annotation = annotation
}
return anView
}
}
最佳答案
您可以提前渲染 VC,然后从屏幕外以模态呈现方式呈现它。如果您绝对必须从您的 UINavigationController 推送,那么在推送 VC 之后,您将等待 VC 调用其 View 的绘制方法。
不过,您还可以提前做其他事情。使用 DetailFeedViewController 以外的东西作为您的 CLLocationManagerDelegate 和 MKMapDelegate。如果这样做,您可以在推送 VC 之前获取用户位置、设置 map 坐标并添加注释。
关于ios - 在导航 Controller 上推送的 viewController 中实现 MapKit 的有效方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42591575/