加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 05:42:34 所属栏目:百科 来源:网络整理
导读:我试图使用核心动画来突出显示一个文本字段是无效的. [[my_field animator] setBackgroundColor [NSColor yellowColor]] 更新字段背景颜色,但不会更改动画.更新属性,如字段的位置适当地动画.我假设这是因为NSAnimatablePropertyContainer搜索中没有包含背景
我试图使用核心动画来突出显示一个文本字段是无效的.
[[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];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读