Fade out, render animation in uilabel

I have a shortcut that I want to fade out and then fade. 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 disappears and then i don't see the fadeout animation. how can i fix this?

+6
source share
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]; } 
+11
source

The call to setAnimationDidStopSelector should be before the animation is setAnimationDidStopSelector :

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationDuration:2]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; scoreLabel.alpha = 1; [UIView commitAnimations]; 
+2
source

Source: https://habr.com/ru/post/919828/


All Articles