ios - MK map View : Animate Drawing of MKPolyline Between Locations

标签 ios swift animation mkmapview mkpolyline

我在 MKMapView 中使用 MKPolyline 在位置之间绘制直线

let locations:[CLLocationCoordinate2D] = ...

let polyLine = MKPolyline(coordinates: locations, count: locations.count)
mapView.add(polyLine)

// MKMapViewDelegate

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
        let renderer = MKPolylineRenderer(overlay: overlay)
        renderer.strokeColor = UIColor.red
        renderer.lineWidth = 4.0
        return renderer
    }

enter image description here

现在我想显示从一个坐标到另一个坐标的线的绘制动画,而不是已经画好的线。有没有可能这样做?任何想法将不胜感激。

最佳答案

从你的坐标数组中,在第一项和第二项之间画一条折线,比如在 0.1 秒内,然后用第一项绘制到第三项,依此类推,直到用计时器从第一项绘制到最后一项,你可以有从源到目的地的动画绘制

关于ios - MK map View : Animate Drawing of MKPolyline Between Locations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48557371/

相关文章:

ios - 访问 socket 时发现为零

Swift AVPlayer 到耳机

javascript - Google 如何在 Google Ideas 主页上创建扭曲效果?

android - 给 ClassCastException 的 ListView 的动画标题

ios - 我应该在 iOS 中制作我的 ivars 属性吗?

iphone - 在屏幕外捕获 MKMapView 屏幕截图

iOS App 在模拟器上运行良好,但在真正的 iOS 设备上崩溃

ios - 如何对要添加的单元格进行排序,将其添加到先前单元格的顶部还是先前单元格的底部

ios - 为什么在页面 View Controller 中使用 KVO 进行观察时应用程序崩溃?以及如何使 KVO 生效?

android - RecyclerView自定义变化动画