is there a way to perform UIModalTransitionStyleCo

2020-07-10 11:30发布

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!

1条回答
不美不萌又怎样
2楼-- · 2020-07-10 11:45

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);
查看更多
登录 后发表回答