Here is some code I struggle with for a while.
If you start the fade in animation, the label text fades in. If I start the fade out animation the the label text fades out.
When I start the startFade
method, only fade out is shown. How can I wait for the fadeIn
method to finish visually before starting the fadeOut
method.
-(IBAction)startFade:(id)sender{
[self fadeIn];
[self fadeOut];
}
-(IBAction)fadeIn:(id)sender{
[self fadeIn];
}
-(IBAction)fadeOut:(id)sender{
[self fadeOut];
}
-(void) fadeIn{
[_label setAlpha:0];
[UILabel beginAnimations:NULL context:nil];
[UILabel setAnimationDuration:2.0];
[_label setAlpha:1];
[UILabel commitAnimations];
}
-(void) fadeOut{
[UILabel beginAnimations:NULL context:nil];
[UILabel setAnimationDuration:2.0];
[_label setAlpha:0];
[UILabel commitAnimations];
}
The fade in and fade out animations can be combined using
UIView.animate(withDuration: animations:)