objective-c – 如何使用核心动画来动画化NSTextField的背景颜色?

我试图使用核心动画来突出显示一个文本字段是无效的.
[[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];

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...