CAEmitterCell 颜色上的 CAKeyframeAnimation 不起作用

CAKeyframeAnimation on CAEmitterCell color not working

我尝试了所有方法,但无法使用 CAKeyframeAnimation 为 CAEmitterCell 的颜色 属性 设置动画。奇怪的是:我可以为几乎所有其他东西制作动画(还没有尝试过所有东西,但似乎是这样)。例如:动画化包含 CAEmitterCell 的 CAEmitterLayer 的 backgroundColor 是没有问题的。还可以为 CAEmitterCell 比例设置动画。

这是我的代码的简化版本:

let cell = CAEmitterCell()
...
cell.name = "main"
emitter.emitterCells = [cell]

let keyPath = "emitterCells.main.color"
// Uncomment this to see that the keyPath works correctly:
//emitter.setValue(UIColor(red: 1, green: 0, blue: 0, alpha: 1).cgColor, forKeyPath: keyPath)
...
let backColorPath = "backgroundColor"
// Use this to see that color animation is basically possible:
//let anim2 = CAKeyframeAnimation(keyPath: backColorPath)
let anim2 = CAKeyframeAnimation(keyPath: keyPath)
anim2.beginTime = CACurrentMediaTime()
anim2.duration = 5
anim2.keyTimes = [0, 0.25, 0.5, 0.75, 1]
anim2.repeatCount = 20
anim2.values = [UIColor.red.cgColor, UIColor.blue.cgColor,
            UIColor.yellow.cgColor, UIColor.cyan.cgColor,
            UIColor.magenta.cgColor]
emitter.add(anim2, forKey: "coloring")

有人知道我哪里出错了吗?

这是 Apple 库中的一个错误,他们在 iOS11.

中修复了它