I am trying to create an animation where I change the color of a rectangle from orange to blue. Here is where I created the rectangle and set its background color to orange:
let colorView = UIView(frame: CGRect(x: 250, y: 500, width: 75, height: 75))
colorView.backgroundColor = UIColor.orange
and here is where I add the animation with the function definition of the animation below it
let colorChangeAnimation = constructColorChangeAnimation()
colorView.layer.add(colorChangeAnimation, forKey: "color")
private func constructColorChangeAnimation() -> CABasicAnimation {
let ColorChangeAnimation = CABasicAnimation(keyPath: "backgroundColor")
ColorChangeAnimation.fromValue = UIColor.orange
ColorChangeAnimation.toValue = UIColor.blue
return ColorChangeAnimation
}
This implementation doesn't seem to work and I'm not sure what it is I need to change. The documentation says that the fromValue and toValue should be the way to change the animation but it just doesn't seem to want to work. (also fyi I did originally have a duration variable for the animation function but it also wasn't working then)

you should use UIColor.orange.cgColor
and UIView animation is much easier