ios - 在导航 Controller 上推送的 viewController 中实现 MapKit 的有效方法?

标签 ios swift mapkit

我正在尝试在 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/

相关文章:

ios - Gif 在 iOS 设备上崩溃

ios - iAd ADBannerView改变SKScene的大小

ios - 如何使用 swift 获取 iOS 构建版本?前 : iOS 11. 3 (15E216)

iphone - 将 MKMapView 上的距离转换为 UIView 的距离

ios - 尽管设置了委托(delegate),但未调用 searchBarSearchButtonClicked

ios - 将数据传递给子容器 View

ios - 全局初始化变量在 Swift UIView XIB 中更改为 'nil'?

ios - Xcode 快疯了!在编码时,丢失类、引用并且不会自动完成,经常给出 <<error type>>

iphone - 如果用户说 "no",如何让位置服务继续提示

ios - 如何在 Swift 中的闭包/ block 中设置属性