James Richard
James Richard

Reputation: 1535

Dismissing a modal view controller using a different animation than it was presented with

I have an application that presents a view controller (for registering / logging in) with a container view, and two views as switched between eachother using horizontal flipping. The app itself can be used before registration. I'm looking to change the way this is handled with storyboarding.

So upon opening the app there's a login button. If the user taps login a view controller is presented using Cover Vertical animation. On the top left of this view controller is a button to Register. Tapping on that does modal segue with a Horizontal Flip animation. On the Register view controller there's Login and Cancel buttons. I want Login to return to the login screen, and Cancel to go back to the view controller that was displayed using the Cover Vertical animation. Getting it there is fine, but the animation used is the Horizontal Flip animation, and not a (un)Cover Vertical animation.

I'ved tried the following code:

self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

before dismissing the view controller, but it's still flipping instead of uncovering.

Thanks for the help!

~James

Upvotes: 2

Views: 2610

Answers (2)

sazz
sazz

Reputation: 3291

for Swift you can call this:

viewController.modalTransitionStyle = .coverVertical
viewController.dismiss(animated: true, completion: nil)

Upvotes: 0

Tobias Tovedal
Tobias Tovedal

Reputation: 731

I see no reason that shouldn't work, but as an example here's the code I would use:

[self setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self dismissModalViewControllerAnimated:YES];

I suggest trying this, it works well for me.

Upvotes: 8

Related Questions