Rei*_*els 9 macos cocoa core-animation objective-c
我正在尝试使用核心动画将文本字段突出显示为无效.
[[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)
有关完成此事的建议吗?
Arv*_*vin 16
圣诞节快乐:
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"];
Run Code Online (Sandbox Code Playgroud)
这将使用支持的图层为视图的背景颜色设置动画.记得在init或awake中设置want层:
[[[self window] contentView] setWantsLayer:YES];
Run Code Online (Sandbox Code Playgroud)
虽然我从未弄清楚如何设置背景颜色的动画,但我能够通过动画CIFalseColor滤镜来创建所需的效果.
CIFilter *filter = [CIFilter filterWithName:@"CIFalseColor"];
[filter setDefaults];
[filter setValue:[CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] forKey:@"inputColor0"];
[filter setValue:[CIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0] forKey:@"inputColor1"];
[filter setName:@"pulseFilter"];
[[myField layer] setFilters:[NSArray arrayWithObject:filter]];
CABasicAnimation* pulseAnimation = [CABasicAnimation animation];
pulseAnimation.keyPath = @"filters.pulseFilter.inputColor1";
pulseAnimation.fromValue = [CIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
pulseAnimation.toValue = [CIColor colorWithRed:0.995 green:1.0 blue:0.655 alpha:1.0];
pulseAnimation.duration = 0.3;
pulseAnimation.repeatCount = 1;
pulseAnimation.autoreverses = YES;
[[myField layer] addAnimation:pulseAnimation forKey:@"pulseAnimation"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9913 次 |
| 最近记录: |