相关疑难解决方法(0)

如何使用核心动画为NSTextField的背景颜色设置动画?

我正在尝试使用核心动画将文本字段突出显示为无效.

[[my_field animator] setBackgroundColor [NSColor yellowColor]]
Run Code Online (Sandbox Code Playgroud)

更新字段背景颜色,但不为更改设置动画.更新属性(例如字段的位置)可以正确设置动画.我假设这是因为NSAnimatablePropertyContainer搜索中不包含背景颜色.

我也试过明确地创建动画,但没有用.

CABasicAnimation *ani;
ani = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];

ani.fromValue = CGColorCreateGenericRGB(1.0,1.0,1.0,1.0);
ani.toValue = CGColorCreateGenericRGB(1.0,0.0,0.0,1.0);
ani.repeatCount = 2;
ani.autoreverses = YES;
ani.duration = 1.0;

[[my_field layer] addAnimation:ani forKey:"backgroundColor"];
Run Code Online (Sandbox Code Playgroud)

有关完成此事的建议吗?

macos cocoa core-animation objective-c

9
推荐指数
2
解决办法
9913
查看次数

如何在动画期间更改CALayer的颜色?

我希望图层从绿色开始,然后慢慢变为黄色,橙色,最后是红色.我该怎么做呢?

CAShapeLayer *layer = [CAShapeLayer layer];
[layer setStrokeColor:[UIColor greenColor].CGColor];
[layer setLineWidth:5.0f];
[layer setFillColor:[UIColor clearColor].CGColor];

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:button.bounds cornerRadius:10.0f];
layer.path = path.CGPath;

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];
animation.duration = 4.0f;

[layer addAnimation:animation forKey:@"myStroke"];
[button.layer addSublayer:layer];
Run Code Online (Sandbox Code Playgroud)

objective-c calayer ios

4
推荐指数
1
解决办法
7117
查看次数

标签 统计

objective-c ×2

calayer ×1

cocoa ×1

core-animation ×1

ios ×1

macos ×1