【发布时间】:2017-11-15 08:37:07
【问题描述】:
使用以下代码,我可以从左到右为 CALayer 设置动画
let imageLayer = CALayer()
imageLayer.frame = CGRect(x: 0, y: 500, width: 100, height: 70)
imageLayer.contents = UIImage(named: "first_image")?.cgImage
let animation = CABasicAnimation()
animation.keyPath = "position.x"
animation.fromValue = 100
animation.toValue = 300
animation.duration = 3
animation.fillMode = kCAFillModeForwards
animation.isRemovedOnCompletion = true
animation.repeatCount = 2
imageLayer.add(animation, forKey: "basic")
self.view.layer.addSublayer(imageLayer)
我想做的是,在
循环:1 - “first_image”将从左向右移动
在
循环:2 - “second_image”(这是另一张图片)将从左侧移动 像上一个周期一样向右。
这里 Cycle: 1 + Cycle: 2 实际上是一个动画,我希望这个动画发生多次。如何做到这一点? 任何帮助将不胜感激。
【问题讨论】:
标签: ios swift cabasicanimation