我试图使用核心动画来突出显示一个文本字段是无效的.
[[my_field animator] setBackgroundColor [NSColor yellowColor]]
更新字段背景颜色,但不会更改动画.更新属性,如字段的位置适当地动画.我假设这是因为NSAnimatablePropertyContainer搜索中没有包含背景颜色.
我也试图明确地创建动画,无济于事.
CABasicAnimation *ani; ani = [CABasicAnimation animationWithKeyPath:@"backgroundColor"]; ani.fromValue = CGColorCreateGenericRGB(1.0,1.0,1.0); ani.toValue = CGColorCreateGenericRGB(1.0,0.0,1.0); ani.repeatCount = 2; ani.autoreverses = YES; ani.duration = 1.0; [[my_field layer] addAnimation:ani forKey:"backgroundColor"];
完成这个建议?
解决方法
圣诞节快乐:
NSView *content = [[self window] contentView]; CALayer *layer = [content layer]; CABasicAnimation *anime = [CABasicAnimation animationWithKeyPath:@"backgroundColor"]; anime.fromValue = (id)[layer backgroundColor]; anime.toValue = (id)CGColorCreateGenericGray(0.0f,1.0f); anime.duration = 5.0f; anime.autoreverses = YES; [layer addAnimation:anime forKey:@"backgroundColor"];
这将使用支持的图层动画化视图的背景颜色.记住要在init或awake中设置需求层:
[[[self window] contentView] setWantsLayer:YES];