views:

174

answers:

1

I'm using objective-c (obviously, I guess) and I'm wondering if there is a (simple) way to present a modal view but have the view slide in from the right side of the screen.

UIModalTransitionStyleCoverVertical has the new view slide in from the bottom, so I would naively think that there would be a Horizontal counterpart, but I can't find one in the docs.

I don't mean UIModalTransitionStyleFlipHorizontal (I don't want the 3D flip).

Is there another way to do this without the baggage of a UINavigationController? Thoughts?

TKS!

+2  A: 

You can do this by adding the view as a subview, but setting its transform so that it is positioned off-screen, by at least one screen width in your case. Then start an animation block that includes resetting the transform to unity. Once the animation is complete you can perform other actions, such as replacing the view that is now hidden.

Here is a snippet:

[[outgoingView superview] insertSubview:incomingView aboveSubview:outgoingView];
incomingView.transform = [self affineTransformForTransationInDirection:BTRightDirection];

// Set up and start the animation
[UIView beginAnimations:@"cover" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:BTSCREEN_ANIMATION_TIME];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(coverIncomingViewConclusion:finished:context:)];
incomingView.transform = CGAffineTransformIdentity;
self.outgoingView = outgoingView; // Remember the outgoing view
[UIView commitAnimations];

The method affineTransformForTransationInDirection: is a helper that knows the width and height of the screen and returns a transform appropriate for the direction. It does this for a move in from the left:

CGAffineTransformMakeTranslation(-FHScreenWidth(), 0.0);
Steve Weller