ios - 在 Google map 上使用动画在多个位置之间移动标记

标签 ios swift google-maps

我想在两个位置坐标之间移动汽车图标,并且我想通过 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/

相关文章:

ios - 在 TableViewCell 中启用 UIButton 可在更多 Cell 中启用

ios - 我们如何在 iPhone 中检测人脸

swift - 与协议(protocol)的一致性冲突 - 最佳实践

ios - DispatchQueue.asyncAfter 没有像我想象的那样工作?

Android map ItemizedOverlay<Item> 绑定(bind)不匹配

ios - XMPPFramework - 如何接收名册的存在信息以及名册列表?

ios - 不区分大小写的字符串搜索 - iphone

ios - 如何使以下调用中的属性可选(即允许 nil)

javascript - 如何在谷歌地图中使用邮政编码查找位置

android - 无法找到 Google API 使用 map 的 Maven 依赖项