Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fade in, fade out animation to uilabel

i have a label that i want to fade in and then to fade out. here is my code:

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

from this code i get this situation: my label is fade in and then i don't see the fadeout animation. how can i fix it?

like image 898
user1492776 Avatar asked Jul 06 '12 07:07

user1492776


2 Answers

-(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];
}
like image 69
mayuur Avatar answered Sep 28 '22 05:09

mayuur


The call to setAnimationDidStopSelector should be before commit the animations:

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

scoreLabel.alpha = 1;

[UIView commitAnimations];
like image 25
Jonathan Naguin Avatar answered Sep 28 '22 03:09

Jonathan Naguin