【发布时间】:2015-05-17 20:23:35
【问题描述】:
我想为我的 UIView(tintColorDidChange)中的子层设置 backgroundColor 更改动画。
我需要从图层当前的背景颜色动画到新的tint颜色几次(每次不同的tint颜色),所以backgroundColor的模型值需要更新(我不能在动画上使用removedOnCompletion = false )。
使用 CABasicAnimation 如果我不更新模型值,我的颜色变化动画可以正常工作(当然,动画完成后颜色会重置)。 当我尝试更新模型值时,颜色会立即发生变化并且动画会丢失。
我尝试禁用隐式动画并使用CATransation 更新模型值,但动画仍然丢失。
如何更新 backgroundColor 模型值并保持我的淡入淡出动画正常工作?
override func tintColorDidChange() {
super.tintColorDidChange()
let colourAnim = CABasicAnimation(keyPath: "backgroundColor")
colourAnim.toValue = self.tintColor.CGColor
colourAnim.duration = 1.0
self.spinnerLayer?.addAnimation(colourAnim, forKey: "colourAnimation")
CATransaction.begin()
CATransaction.setDisableActions(true)
self.spinnerLayer?.backgroundColor = self.tintColor.CGColor
CATransaction.commit()
}
【问题讨论】:
标签: ios swift animation calayer cabasicanimation