我有两个动画,我试图找出一个结束,然后做我想做的事情。我知道我可以区分使用valueForKey的动画,但我不知道确切的方式。
func myanimation1() {
let pulse1 = CABasicAnimation(keyPath: "transform.scale")
pulse.duration = 0.25
pulse.fromValue = 1
pulse.toValue = 1.05
pulse.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
pulse.autoreverses = true
pulse.repeatCount = 2
// pulse.isRemovedOnCompletion = false
myImageView1.layer.add(pulse, forKey: myKey1)
}
func myanimation2() {
let pulse2 = CABasicAnimation(keyPath: "transform.scale")
pulse2.duration = 0.5
pulse2.fromValue = 1.3
pulse2.toValue = 1.5
pulse2.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
pulse2.autoreverses = true
pulse2.repeatCount = 4
// pulse2.isRemovedOnCompletion = false
myImageView2.layer.add(pulse, forKey: myKey2)
}现在,请怎样做这一点?
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
//if pulse1 ended { do something }
//if pulse2 ended { do something else }
}任何帮助都非常感谢。
发布于 2021-02-16 19:31:41
这里有一个非常酷的秘密:你可以使用键值编码给你的动画一个名字或其他标识。
let pulse2 = CABasicAnimation(keyPath: "transform.scale")
pulse2.setValue("pulse2", forKey:"name")在委托方法中,您将接收动画,因此可以检查该名称:
if let name = anim.value(forKey:"name"), name == "pulse2" ...https://stackoverflow.com/questions/66230861
复制相似问题