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
的實現......使用純色作品)的事實。我仍然在尋找這個問題的答案。