向后播放CABasicAnimation后,CALayer消失

时间:2016-07-10 13:03:56

标签: ios swift core-animation calayer cabasicanimation

我有一个CALayer,我已经像这样添加了一个CABasicAnimation:

circle = CALayer()
circle.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
circle.backgroundColor = UIColor.green().cgColor
circle.cornerRadius = 50
circle.speed = 0
view.layer.addSublayer(circle)

animation = CABasicAnimation(keyPath: "position")
animation.duration = 1
animation.fromValue = NSValue(cgPoint: CGPoint(x: 50, y: 50))
animation.toValue = NSValue(cgPoint: CGPoint(x: view.bounds.width / 2, y: view.bounds.height / 2))
animation.fillMode = kCAFillModeBoth
animation.isRemovedOnCompletion = false
circle.add(animation, forKey: nil)

当我通过将图层的速度设置为-1来向后播放动画时, 图层在动画结束时消失:

circle.timeOffset = 1
circle.speed = -1
circle.beginTime = CACurrentMediaTime()

因此,我使用CADisplayLink向后播放动画,
但是我想知道是否可以通过将速度设置为-1并防止图层消失来实现。

0 个答案:

没有答案