Iphone – How to implement view sliding in and out in iPhone


I would like to implement the effect of a view sliding in, much like the animation of a view being brought in by presentModalViewController, but the view only slides in to cover half the screen.

I approached it this way:

1) Right before thew view should appear and slide in, addSubview the child view. Position it in such a way it's out of view in the beginning.

2) Call a method on the view controller of the subview to perform the Core Animation code to bring it in.

Doing the above didn't seem to work (nothing happens – the view just appears at its starting location). Adding the view ahead of time in viewDidLoad won't work either. Ideally, I would like the code to have the same requirement as presentModalViewController – which requires you to instantiate the view controller at the point you need to bring the view in and animate it.

Would appreciate if you can provide pointer or code on animating the view in/out as well.

Best Solution

I would check out the sample project ViewTransitions on the Apple dev site. It is a great resource for understanding the simple things you need to do when setting up transitions. If you wanted to only slide in half-way you could try setting the frame of the "sliding view" to only half the screen... just check out the code and give it a try.