2012-07-06 9 views
6

나는 페이드 인하 고 페이드 아웃하려는 라벨이 있습니다. 내가이 상황을 얻을이 코드에서페이드 인, 애니메이션 페이드 아웃

-(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]; 
} 

: 여기 내 코드 내 레이블은 페이드 다음 i는 페이드 아웃 애니메이션이 표시되지 않는 것입니다. 어떻게 해결할 수 있습니까?

답변

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

감사를! setAnimationDelagate를 사용하는 것을 잊었습니다. 이제 완벽하게 작동합니다! – user1492776

+0

환영 .. 만약 그것이 다음 upvote 작동하고 대답을 받아 :) – mayuur

2

setAnimationDidStopSelector에 대한 호출은 이전 애니메이션을 커밋해야합니다

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

scoreLabel.alpha = 1; 

[UIView commitAnimations]; 
관련 문제