2012-07-06 34 views
6

tôi có một nhãn mà tôi muốn mờ dần và sau đó mờ dần. đây là mã của tôi:mờ dần, làm mờ hình động thành 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]; 
} 

từ mã này tôi nhận được tình trạng này: nhãn của tôi là phai trong và sau đó tôi không nhìn thấy hình ảnh động fadeout. làm thế nào tôi có thể sửa chữa nó?

Trả lờ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

cảm ơn! tôi quên sử dụng setAnimationDelagate, bây giờ nó hoạt động hoàn hảo! – user1492776

+0

welcome .. Nếu nó hoạt động thì upvote và chấp nhận câu trả lời :) – mayuur

2

Các cuộc gọi đến setAnimationDidStopSelector nên trước khi cam kết các hình ảnh động:

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

scoreLabel.alpha = 1; 

[UIView commitAnimations]; 
Các vấn đề liên quan