ios - 在 Google 地图上使用动画在多个位置之间移动标记
问题描述
我想在两个位置坐标之间移动汽车图标,并且我想通过滑块更改该汽车图标的持续时间(速度)。
我尝试 CATransaction 为标记设置动画。它的动画效果很好,但我无法通过滑块实时更改持续时间(速度)。
这是我为标记设置动画的代码。
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))
}
标记(汽车)图标应该在两个坐标之间移动,如果用户通过左右移动滑块来改变速度值,动画持续时间应该会受到影响。
解决方案
您无法更改飞行中动画的持续时间。
您应该能够更改图层的速度参数以加快速度。
Speed = 1.0 是正常速度。速度 2.0 将快两倍(持续时间的一半)。0.5 的速度将是半速。
你会使用像这样的代码
marker.layer.speed = 2.0
(您需要重构以设置滑块的速度。尝试从 0.5 到 1.5 的范围。)
推荐阅读
- reactjs - 在 SQL 中接收不正确的时间
- java - 尝试通过 https 使用休息时连接被拒绝
- r - 自举置信区间对数响应比
- python - TypeError:无法转换类型的输入
到时间戳 - spring-boot - 如何在微服务架构中优雅地处理 pod 关闭
- javascript - 使用箭头函数时未定义的虚拟字段猫鼬
- supertest - 针对未处理的 Supertest 请求的 MSW 日志记录警告
- typescript - 数组中泛型参数的打字稿联合
- fetch-api - 如何在 Dialogflow GUI 上使用 fetch 显示 API 数据
- python - google.cloud.storage 允许访问,但 gcsfs 不允许