Tutorial :UIView Animation: Shrink


I'm looking to have my main view shrink to reveal the next view in the same way the Facebook app's views shrink when you press the top-left button. I already have it working with one of the included animations like this:

[UIView beginAnimations:nil context:nil];    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];    [UIView setAnimationDuration:1.0];    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];    [self.navigationController popToRootViewControllerAnimated:YES];    [UIView commitAnimations];  

However, since "Shrink" isn't one of the included animations, I'm a bit stuck. How could I make this shrink instead?

I'm fairly well-experienced with the iPhone SDK but haven't spent a lot of time with UIView animations.


Have you tried combining a scaling and translating transformation?


UIView's setAnimationTransition: method makes the packaged set of animations dirt simple, but if you want to do something else, you have to drop down a level and use Core Animation itself.

It isn't too bad: basically you use CATransaction's begin and commit methods and in between, get the view's layer and set its transform property directly. To shrink it you could set the scale to 0.00001, causing it to shrink.

Instead of removing the view right away, you will have to set a completion block and remove it yourself when the animation is done. And you might want to reset the transform back to normal, if you plan to use the view again.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »