2012-07-06 17 views
6

için karartmak istiyorum. Solmaya ve sonra da solmaya çalışmak istediğim bir etiketim var. ben bu durumu olsun bu koddansoluklaşıyor, animasyonu uilabel

-(void) fadein 
{ 
    scoreLabel.alpha = 0; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    [UIView setAnimationDuration:2]; 
    scoreLabel.alpha = 1; 
    [UIView commitAnimations]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
} 



-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:2]; 
scoreLabel.alpha = 0; 
[UIView commitAnimations]; 
} 

: burada benim kodudur benim etiket solmaya ve sonra ben fadeout animasyon görmüyoruz. Nasıl düzeltebilirim?

cevap

11
-(void) fadein 
{ 
    scoreLabel.alpha = 0; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 

    //don't forget to add delegate..... 
    [UIView setAnimationDelegate:self]; 

    [UIView setAnimationDuration:2]; 
    scoreLabel.alpha = 1; 

    //also call this before commit animations...... 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
    [UIView commitAnimations]; 
} 



-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:2]; 
    scoreLabel.alpha = 0; 
    [UIView commitAnimations]; 
} 
+0

teşekkür! setAnimationDelagate kullanmayı unuttum, şimdi mükemmel çalışıyor! – user1492776

+0

welcome .. Çalıştıysa daha sonra cevap verin ve cevabı kabul edin :) – mayuur

2

setAnimationDidStopSelector çağrısı önce animasyonlar taahhüt edilmelidir:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView setAnimationDuration:2]; 
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 

scoreLabel.alpha = 1; 

[UIView commitAnimations];