我尝试了所有内容,但我无法使用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")
有谁知道我哪里出错了?
答案 0 :(得分:0)
这是Apple库中的一个错误,他们在iOS 11中修复了它。