2011-01-10 4 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을 생략하고 keypath를 @ "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"]; 

이 백업 된 레이어를 사용하여 뷰의 배경 색상을 애니메이션 것입니다. 초기화 또는 깨어있는 레이어를 원하는 설정 기억

[[[self window] contentView] setWantsLayer:YES]; 
관련 문제