Question

I'm having a little trouble with dismissViewControllerAnimated, I can't get it to perform a certain transition.

I have a view controller (home), and I'm opening another VC (login) using a modal. I can then navigate between 2 modals (login & register), but I'd like a button to return to my first view controller (home).

           HOME
            |
            |
            |Modal
            |
            |
  LOGIN----------REGISTER
       <- Modal ->

Now the transition between Login and Register is set to Horizontal Flip. This is fine.

On my Login view, I have a button which dismisses the modals, to get back to Home. But the transition is always the same as the previous transition used, (horizontal flip in this case)

Even specifying a modalTransitionStyle it doesn't help, it still uses the previous style.

Any ideas are greatly appreciated. Below is what I've tried so far.

- (IBAction)cancelAccount:(id)sender {

    self.view.window.rootViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self.view.window.rootViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}

Thanks, Adrian

Was it helpful?

Solution

These lines both do the same thing:

self.view.window.rootViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.view.window.rootViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

so you only need to use 1 of them.

But also, you should be setting the transition style on the view controller which is actually transitioning, not on the root view controller (which is only managing the transition process).

i.e. set the transition style on the login and register view controllers before dismissing them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top