【发布时间】:2011-04-09 14:29:03
【问题描述】:
我正在尝试使用此代码为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 的实现......使用纯色有效)。我还在寻找这个问题的答案。
【问题讨论】:
标签: iphone objective-c core-animation calayer