2011-05-03 6 views
0

코코아 터치에서 깜박이는 UILabel을 만들 수 있습니까? 아니면 코어 애니메이션과 함께 UIview가 필요합니까?UILabel 코코아 터치 깜박임

+0

** 경고! ** 깜박이는 사용자 인터페이스 요소는 특정 주파수에서 깜박이는 경우 간질 발작을 유발할 수 있습니다. 그러한 애니메이션을 구현할 때는주의하십시오. –

답변

0

재미를 위해, 나는이 서브 클래스 NSOperation을 쓰기로했다. 샘플보기 컨트롤러 코드

- (void)main { 
    SEL update = @selector(updateLabel); 
    [self setThreadPriority:0.0]; 

    while (![self isCancelled]) { 
     if (label_ == nil) 
      break; 

     [NSThread sleepForTimeInterval:interval_]; 
     [self performSelectorOnMainThread:update withObject:nil waitUntilDone:YES]; 
    } 
} 

- (void)updateLabel { 
    BlinkingColors *currentColors = nil; 

    if (mode_) 
     currentColors = blinkColors_; 
    else 
     currentColors = normalColors_; 

    [label_ setTextColor:currentColors.textColor]; 
    [label_ setBackgroundColor:currentColors.backgroundColor]; 

    mode_ = !mode_; 
} 

BlinkingLabelOperation.m

에서

발췌 :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    BlinkingColors *blinkColors = [[BlinkingColors alloc] initWithBackgroundColor:[UIColor whiteColor] 
                     textColor:[UIColor redColor]]; 

    BlinkingLabelOperation *blinkingOp = [[BlinkingLabelOperation alloc] initWithLabel:clickLabel freq:1.0 blinkColors:blinkColors]; 

    // put the operation on a background thread 
    NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; 
    [queue addOperation:blinkingOp]; 

    [blinkColors release]; 
} 

전체 목록은, 당신이 그것을 here을 찾을 수 있습니다. 의견을 남기고 당신의 생각을 알려주십시오.

+0

안녕 검은 개구리, 당신의 답변과 당신의 코드에 대해 많이 감사합니다! 구현하기가 쉽고 멋지며 훌륭하게 작동하며 정확하게 찾고 있습니다. 두 가지 엄지 손가락 :-) – Winston

1

모든 UIView (UILabel 포함)는 켜기/끄기를 전환하여 "깜박"하게 할 수있는 hidden 속성을 가지고 있습니다.

+0

Martin, 지적 해 주셔서 고맙습니다. 이 시점에서 UILabel은 나의 필요에 부합합니다. – Winston

+0

UILabel은 UIView입니다. –

2

Martin의 조언을 듣고 NSTimer을보고 "깜박임"작업을 처리하십시오.

+ scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:

+0

환상적으로 보이고 싶다면 알파 값으로 애니메이션을 켜고 끌 수 있습니다. – DavidN

+0

일시 중지 된 오디오 플레이어 상태를 표시하는 것은 단지 3 초입니다. 아무것도 유해한. 감사. – Winston

+0

제안 사항도 적용됩니다. 관심을 가져 주셔서 감사합니다. – Winston