我想在两个位置坐标之间移动汽车图标,并且我想通过 slider 更改该汽车图标的持续时间(速度)。
我尝试使用 CATransaction 来对标记进行动画处理。它的动画效果很好,但我无法通过 slider 实时更改持续时间(速度)。
这是我的标记动画代码。
func moveTo(point: CLLocationCoordinate2D) {
if let marker = arrMapList[0] as? GMSMarker {
let angle = getAngle(fromLoaction: marker.position, toLocation: points[currentIndex])
marker.rotation = CLLocationDegrees(angle * (180.0 / .pi))
CATransaction.begin()
CATransaction.setAnimationDuration(5)
CATransaction.setCompletionBlock {
if let nextPoint = self.getNextPoint(currentIndex: self.currentIndex) {
self.moveTo(point: nextPoint)
}
}
marker.position = point
CATransaction.commit()
}
}
我尝试按如下方式更改持续时间,但它不起作用。
@IBAction func SliderValueChanged(_ sender: UISlider) {
CATransaction.setAnimationDuration(CFTimeInterval(sender.value))
}
标记(汽车)图标应在两个坐标之间移动,如果用户通过向左或向右移动 slider 更改速度值,则应影响动画持续时间。
最佳答案
您无法更改飞行中动画的持续时间。
您应该能够更改图层的速度参数以加快速度。
速度 = 1.0 是正常速度。 Speed 2.0 的速度将是原来的两倍(持续时间的一半)。 0.5 的速度是半速。
你会使用像
这样的代码marker.layer.speed = 2.0
(您需要重构以设置 slider 的速度。尝试使用 0.5 到 1.5 的范围。)
关于ios - 在 Google map 上使用动画在多个位置之间移动标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58224167/