Fade in / fade out a view, iOS Objective C

Fade in / fade out a view, iOS Objective C

Just want to give some kudos to this answer on Stackoverflow.

[cc lang=”objc” escaped=”true” width=”90%” theme=”default” line_numbers=”on”]
// 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];
}
}