2010-04-07 2 views
2

я получил следующий код внутри селектора NSTimer:UILabel плавного вопроса перепыл из

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:2.0]; 
[infoLbl setAlpha:0]; 
[UIView commitAnimations]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:2.0]; 
[infoLbl setAlpha:1]; 
[UIView commitAnimations]; 

Так что я хочу реализовать простой выцветанию в/исчезать из петли на платформе UILabel (infoLbl).

Ну, с этим кодом я получаю только шаг затухания, так как UILabel внезапно исчезает, затем исчезает.

Некоторое предложение?

Спасибо.

ответ

10
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
[UIView setAnimationDuration:2.0]; 
[infoLbl setAlpha:0]; 
[UIView commitAnimations]; 

//This delegate is called after the completion of Animation. 
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:2.0]; 
    [infoLbl setAlpha:1]; 
    [UIView commitAnimations]; 

} 

Insetad этого, если вы используете NSTimer Selecor, то у Dont U Tryout изменяя цвет текста UILabel? например:

-(void)timerSelector 
{ 
    if([textLabel textColor] == [UIColor blackColor]) 
    { 
     [textLabel setTextColor:[UIColor grayColor]]; 
    } 
    else 
    { 
     [textLabel setTextColor:[UIColor blackColor]]; 
    } 
} 

Вышеуказанный метод позволит вам легко или просто затухать в петле.

+0

ДА! Благодаря! (Я использовал первый образец). –

0

Затушите сначала, установив animationDidStopSelector: и внутри селектора (см. Документацию для получения дополнительной информации), скажите, чтобы оно исчезло.

+0

Хорошо, я сделал это: - (void) fadeLoop { \t [self fadeIn]; } - (void) fadeIn { \t [UIView beginAnimations: nil context: NULL]; \t [UIView setAnimationDuration: 2.0]; \t [UIView setAnimationDidStopSelector: @selector (fadeOut: finished: context :)]; \t \t [infoLbl setAlpha: 1.0]; \t [UIView commitAnimations]; } - (void) fadeOut: (NSString *) animationID закончен: (BOOL) законченный контекст: (void *) контекст { [UIView beginAnimations: nil context: context]; [UIView setAnimationDuration: 2.0]; infoLbl.alpha = 0.0; [UIView commitAnimations]; } теперь он не исчезает и не исчезает –

+0

Установите анимациюДелегат первой анимации для себя. –

Смежные вопросы