tags:

views:

643

answers:

3

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.

A: 

Maybe you should post the code you use in step number 2. I did something similar on one of my apps, where the user slides a view from one edge of the screen to the other as if placeing a cover over the screen.

If what you are trying to do is an automatic animation (without user interaction) I believe that you need to: set to the sliding view a frame representing the final position. Do this within an animation block. Play with the duration, animation curve, etc parameters.

nico
A: 

Check my answer http://stackoverflow.com/questions/1026403/animating-the-display-of-a-view/1028897#1028897. It shows how to animate a UIView.

Ron Srebro
+1  A: 

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.

Ryan Ferretti