2011-01-10 6 views
9

コア・アニメーションを使用してテキスト・フィールドを無効として強調表示しようとしています。コアアニメーションを使用してNSTextFieldの背景色をアニメーション化するにはどうすればよいですか?

[[my_field animator] setBackgroundColor [NSColor yellowColor]] 

フィールドの背景色を更新しますが、変更をアニメートしません。フィールドの位置などのプロパティを更新すると、適切にアニメートされます。背景色が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"]; 

これを達成するための提案はありますか?

答えて

5

バックグラウンドカラーをアニメーション化する方法を考え出すことはできませんでしたが、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"]; 
+0

パブリック10.11(エルキャピタン)のベータ版では、カスタムフィルタ(カスタム名のフィルタ)の適用はサポートされていないようです。ただし、コードはsetName-lineを省略し、キーパスを@ "filters。CIFalseColor.inputColor1"に設定すると機能します。直接。 – deflozorngott

+1

10.9以降では、self.layerUsesCoreImageFilter = YESを追加する必要があります。 – deflozorngott

15

メリークリスマス:

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"]; 

これは、バックアップされた層を使用してビューの背景色をアニメーション化します。

関連する問題