I'm attempting to use this code to animate a CALayer's background color:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
animation.duration = 0.3;
animation.fromValue = (id)[backgroundLayer backgroundColor];
animation.toValue = (id)[[UIColor redColor] CGColor];
[backgroundLayer addAnimation:animation forKey:@"animateBackgroundColor"];
For some reason, this doesn't do anything. Simply using:
[backgroundLayer setBackgroundColor:[[UIColor redColor] CGColor]];
works (although without animation) and using:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration=0.3;
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
[backgroundLayer addAnimation:animation forKey:@"animateOpacity"];
works, too (with animation).
Why can't I animate the background color?
EDIT: The problem is related to the fact that my backgroundColor is created with a pattern image (using UIImage's implementation... Using solid colors works). I'm still looking for the answer to this problem.