1
我试图使用此代码动画一个CALayer
的背景色:核心动画 - 动画不起作用
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"];
出于某种原因,这并不做任何事情。只需用:
[backgroundLayer setBackgroundColor:[[UIColor redColor] CGColor]];
作品(虽然没有动画),并使用:
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"];
作品,太(动画)。
为什么我不能为背景颜色设置动画效果?
编辑:的问题与我的backgroundColor
率与图案图像创建(使用UIImage
的实现......使用纯色作品)的事实。我仍然在寻找这个问题的答案。