Ich versuche, eine sehr einfache CAGradientLayer
Animation zu arbeiten. Ich habe eine grundlegende 2 Farbe CAGradientLayer
eingerichtet und hinzugefügt, um meine UIViewController
.CAGradientLayer Farbwechsel Animation nicht ausgeführt
// Set up the gradient layer.
var gradientLayer: CAGradientLayer! {
let layer = CAGradientLayer()
layer.frame = self.view.bounds
layer.colors = [UIColor.redColor().CGColor, UIColor.yellowColor().CGColor]
layer.locations = [0.0, 1.0]
return layer
}
Ich versuche es mit dem folgenden Code zu animieren:
@IBAction func changeBackground(sender: AnyObject) {
let oldColors = self.gradientLayer.colors
let newColors = [UIColor.purpleColor().CGColor, UIColor.blueColor().CGColor]
self.gradientLayer.colors = newColors
let animation: CABasicAnimation = CABasicAnimation(keyPath: "colors")
animation.fromValue = oldColors
animation.toValue = newColors
animation.duration = 0.3
animation.removedOnCompletion = true
animation.fillMode = kCAFillModeForwards
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.delegate = self
self.gradientLayer.addAnimation(animation, forKey: "animateGradientColorChange")
}
jedoch dieser Code nicht nachgibt im CAGradientLayer
jede Änderung. Was mache ich hier falsch?