简体   繁体   English

在导航控制器上推送的viewController中实现MapKit的有效方法?

[英]Efficient way to implement MapKit in a viewController that is push on Navigation Controller?

I am trying to add a mapKit in a viewController in IB that I am pushing on top of my navigation controller but no matter where in the cycle I add the annotations it seems like the whole thing causes a delay and until mapKit is not rendered the scrollview that contains everything doesn't scroll easily. 我正在尝试在IB的viewController中添加mapKit,将其推到导航控制器的顶部,但是无论在循环中的何处添加注释,似乎整个事情都会导致延迟,直到mapKit不呈现为scrollview包含所有内容的内容不会轻易滚动。 Is there a way to do this in iOS similar to Android in the background threads for instance? 例如,有没有一种方法可以在iOS中像后台线程一样在Android中执行此操作?

Below is the code even without adding any annotation, rendering is still causing the delay. 下面的代码即使没有添加任何注释,渲染仍然会导致延迟。 I'm pretty sure there's another way. 我很确定还有另一种方法。 Any idea? 任何想法?

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
        }

}

You CAN render a VC ahead of time, and present it from offscreen, with a modal presentation. 您可以提前渲染VC,并通过模态演示从屏幕外呈现。 If you absolutely must push from your UINavigationController, then you're stuck waiting for the VC to call the draw methods of its view, after the VC is pushed. 如果绝对必须从UINavigationController进行推送,那么在推送VC之后,您就不得不等待VC调用其视图的draw方法。

There are other things you can do ahead of time, however. 但是,您还可以提前做其他事情。 Use something other than DetailFeedViewController as your CLLocationManagerDelegate, and MKMapDelegate. 使用DetailFeedViewController以外的其他内容作为CLLocationManagerDelegate和MKMapDelegate。 If you do so, you can get the user's location, set the map coordinates, and add you annotation, before the VC is pushed. 如果这样做,则可以在按下VC之前获取用户的位置,设置地图坐标并添加注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导航控制器show / push viewcontroller swift - Navigation Controller show/push viewcontroller swift 导航 Controller 未加载(推送,呈现)另一个视图控制器 - Navigation Controller is not loading ( push , present ) another viewController 以编程方式将视图控制器添加到导航控制器,然后推送另一个视图控制器 - Add viewcontroller to navigation controller programmatically then push another view controller 如何在导航控制器内的storyboard中从appdelegate推送viewcontroller - How to push viewcontroller from appdelegate in storyboard inside navigation controller 故事板-ViewController中的导航控制器 - Storyboard - navigation controller in viewcontroller 在导航控制器中滑动viewController - Slide viewController in navigation controller Ibeacon导航控制器和ViewController - Ibeacon Navigation Controller and ViewController 展示导航控制器的ViewController - Presenting ViewController of a Navigation Controller 如何通过导航 controller iOS 13 从模态呈现的 ViewController 将 ViewController 推送到全屏? - How to push ViewController on full screen from modally presented ViewController with navigation controller iOS 13? 从导航控制器堆栈中删除所有Viewcontroller的最佳方法 - Best way to remove all the Viewcontroller from navigation controller stack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM