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 ou
Try this..
// Fade Out
-(void)fadeOut:(UIView*)viewToDissolve withDuration:(NSTimeInterval)duration andWait:(NSTimeInterval)wait
{
[UIView beginAnimations: @"Fade Out" context:nil];
// wait for time before begin
[UIView setAnimationDelay:wait];
// druation of animation
[UIView setAnimationDuration:duration];
viewToDissolve.alpha = 0.0;
[UIView commitAnimations];
}
// Fade In
-(void) fadeIn:(UIView*)viewToFadeIn withDuration:(NSTimeInterval)duration andWait:(NSTimeInterval)wait
{
[UIView beginAnimations: @"Fade In" context:nil];
// wait for time before begin
[UIView setAnimationDelay:wait];
// druation of animation
[UIView setAnimationDuration:duration];
viewToFadeIn.alpha = 1;
[UIView commitAnimations];
}
// Fade in from fade out
-(void) fadeInFromFadeOut: (UIView*)viewToFadeIn withDuration:(NSTimeInterval)duration
{
viewToFadeIn.hidden=NO;
[self fadeOut:viewToFadeIn withDuration:1 andWait:0];
[self fadeIn:viewToFadeIn withDuration:duration andWait:0];
}
// Button operation
-(void) buttonClicked :(id)sender
{
NSLog(@"Button clicked");
// Each button is given a tag
int tag = ((UIButton*)sender).tag;
if (tag ==1)
{
sprite.alpha =1;
[self fadeOut : sprite withDuration: 10 andWait : 1 ];
}
else if (tag ==2)
{
sprite.alpha =0;
[self fadeIn : sprite withDuration: 3 andWait : 1 ];
}
else
{
[self fadeInFromFadeOut:sprite withDuration:10];
}
}
View this link to download sample..
Refer this link.
Happy to share with you..:-)