CALayer disappears after playing a CABasicAnimation backwards

◇◆丶佛笑我妖孽 提交于 2020-01-04 02:42:35

问题


I have a CALayer and I've added a CABasicAnimation to it like this:

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)

When I play the animation backwards by setting the layer's speed to -1,
the layer disappears at the end of the animation:

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

Because of that, I use CADisplayLink to play an animation backwards,
but I'm wondering if it can be achieved by setting the speed to -1 and preventing the layer from disappearing also.

来源:https://stackoverflow.com/questions/38292169/calayer-disappears-after-playing-a-cabasicanimation-backwards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!