我正在尝试使用核心动画将文本字段突出显示为无效.
[[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)
有关完成此事的建议吗?
我希望图层从绿色开始,然后慢慢变为黄色,橙色,最后是红色.我该怎么做呢?
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)