从数组中的动态坐标动画Google标记移动

时间:2016-04-20 12:46:18

标签: ios swift

我想要从数组中的动态坐标动画Google标记移动。但是标记在一条直线上移动。

我的代码:

for coord in self.lstCoordinate{
    CATransaction.begin()
    CATransaction.setAnimationDuration(2.1) 
    self.Marker.position = coord
    CATransaction.commit()
}

1 个答案:

答案 0 :(得分:0)

找到解决方案。希望能帮助其他人......

var index = 0

func moveMarker(){
    var count: Double = Double(self.lstCoordinate.count)
    CATransaction.begin()
    CATransaction.setAnimationDuration(20.0/count)
    CATransaction.setCompletionBlock
        {
            if self.index == 0{
                self.lstCoordinate.removeAll()
                return;
            }
            else{
                self.moveMarker()
            }                              

    }

    let transition = CATransition()
    transition.type = kCATransitionMoveIn
    self.originMarker.layer.addAnimation(transition, forKey: kCATransition)
    self.Marker.position = lstCoordinate[index]
    CATransaction.commit()

    index = index < lstCoordinate.count - 1 ? index + 1 : 0

}