views:

4426

answers:

1

I can animate the addition of a UIView to my app, it looks very pretty so thank you apple.

However, how do I animate the removal of this view from the super view?

I'm using:

CATransition *animation = [CATransition animation];
[animation setDuration:1];
[animation setType:kCATransitionReveal];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myview layer] addAnimation:animation forKey:kCATransitionReveal];

to animate the "in" transition ... how do you animate the "out" transition????

+8  A: 

Animate your view so it moves offscreen/shrinks/expands/fades, then do the actual removal when the animation ends.

You can do this by altering the properties of the view (position/size/offset) between a beginAnimations/commitAnimations block. UIKit will then animate these properties over the time specified.

E.g something like;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
view.transform = 
  CGAffineTransformMakeTranslation(
    view.frame.origin.x, 
    480.0f + (view.frame.size.height/2)  // move the whole view offscreen
  );
background.alpha = 0; // also fade to transparent
[UIView commitAnimations];

In the animation end notification you can then remove the view.

Andrew Grant
thanks! i suppose that is my question: how i animate the view show it moves offscreen?
Keith Fitzgerald
Ahh, answer update to clarify.. No need to downvote tho!
Andrew Grant
Ahhhh ... thank man I really appreciate it. so weird the offscreen transition isn't baked in. appreciate the help!
Keith Fitzgerald