我尝试了所有的东西,但是我无法用CAEmitterCell的颜色属性与CAKeyframeAnimation动画。奇怪的是:我几乎可以把其他的东西都动画化(没有试过所有的东西,但似乎都是这样)。例如:动画包含backgroundColor的CAEmitterLayer的CAEmitterCell是没有问题的。此外,动画的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")有人知道我哪里出了问题吗?
发布于 2018-04-22 14:49:22
这是苹果图书馆里的一个bug,他们在iOS 11中修复了它。
https://stackoverflow.com/questions/40948180
复制相似问题