"Animate fade in/out"

Mon 11 May 2009

 

IN *.m file  

------------------------------ 

#pragma mark ANIMATION

//-------fade in

-(void)animateFadingIn{

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1.0];

[UIView setAnimationDelegate:self];

//set transformation

[UIView commitAnimations];

}

 

//-------fade out

- (void)animateFadingOut{

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1.0];

[UIView setAnimationDidStopSelector:@selector(fadeAnimationDidStop:finished:context:)];

[UIView setAnimationDelegate:self];

//set transformation

[UIView commitAnimations];

}

- (void)fadeAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{

// push navigation controloller

}

 

 

IN *.h file

 

 -----------------------------

-(void)animateFadingIn;

-(void)animateFadingOut; 

 

 

////////////////////////////////////////////

//SAMPLE: 

logoBackdropView = [[UIImageView alloc] initWithFrame:CGRectMake(-36.0, 120.0, 479, 233)];

logoBackdropView.image = [UIImage imageNamed:@"logo_backdrop.png"];

[self.view addSubview:logoBackdropView]; 

 

 -(void)animateFadingIn{

 

  //state before animation

logoBackdropView.alpha = 0.0;

logoBackdropView.transform = CGAffineTransformMakeScale(2.002.00);

 

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1.0];

[UIView setAnimationDelegate:self];

 

//state after animation

logoBackdropView.alpha = 1.0;

logoBackdropView.transform = CGAffineTransformMakeScale(1.00, 1.00);

[UIView commitAnimations];

}