Justin Grant
Justin Grant

Reputation: 46683

iOS "slide in from left/right" view animations

My iOS6 app has a multi-level table view whose leaf nodes open up separate views. The animation from the first level of the table slides the old view out to the left and the new view in from the right. I'd like to also use this slide-in animation when transitioning from a table view to a non-table view. How?

Here's more info:

On the first level of the table view, there are disclosure Indicators enter image description here. When one is clicked, the first level of the table slides off to the left and the second level view slides in from the right. Good.

On the second level of the table, there are Detail Disclosure Buttons enter image description here which take the user to a detail view for that element in the table.

I'd like to offer the same animation here too: the table view should slide off to the left and the new view should slide in from the right.

First, am I correct that this is the correct animation to use in this case?

Second, do you know why this "slide in" animation isn't in the standard view animations in UIViewAnimationTransition below?

typedef enum {
   UIViewAnimationTransitionNone,
   UIViewAnimationTransitionFlipFromLeft,
   UIViewAnimationTransitionFlipFromRight,
   UIViewAnimationTransitionCurlUp,
   UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;

Finally, if I do want to use the same slide in animation that table views use, but it's not available as one of the standard views, how should I add this animation when transitioning between a table view and a non-table view?

Upvotes: 3

Views: 6003

Answers (1)

rsswtmr
rsswtmr

Reputation: 1816

Typically this type of animation is done in a UINavigationController, and is the result of pushing a new viewController onto the stack. If you want to simulate it, all you need to do is add the newly exposed view to your current base view, to the right of the current view (i.e. off-screen) and use UIView's animateWithDuration:animations:completion: method to move both the on-screen and off-screen views one screen to the left. (Use the completion: block to remove the original view or leave it in place so you can easily animate it back on-screen.)

Upvotes: 8

Related Questions