Animated transition between two modular ViewControllers

I am trying to switch between two different active Modal View controllers and trying to achieve smooth animation. Ideally, I would like the animation to look just like the new Modal View becomes Modal View over the current Modal View.

For consistency in my application, I need to limit only one layer of Modal View controllers displayed at any given time.

Currently, I just have an existing Modal View fired without animation, and then animate the next Modal View over the RootController, but that doesn't look very good.

thanks

+4
source share
1 answer

You can simply imagine the model controller of the second model compared to the first using the default transition. It looks like your second model view is highlighted and initialized in the same view controller as your first model view. If so, consider refactoring the code so that you have a first model view controller that represents a second modal view controller. Doing this will be displayed one above the other as you want.

If you need to save code to represent both modal view controllers in the same root view, you may need to create a delegate method. This will send a message from the first modal view controller back to the root view controller, which introduced it by passing a link to the first modal view controller. Then use this link to inform the first modal view controller of how to present the second modal view controller above it.

I would definitely recommend the previous solution, although it was logically clearer, with a lesser likelihood of introducing a save cycle.

In response to your clarification:

To jump between the two, try:

In an instance of ModalViewControllerOne , which is already displayed from the previous session:

 self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self dismissModalViewControllerAnimated:YES]; 

In your root controller, -viewDidAppear:

 ModalViewControllerTwo *modalViewControllerTwo = [[ModalViewControllerTwo alloc] init]; modalViewControllerTwo.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [rootViewController presentModalViewController:modalViewControllerTwo animated:YES]; 

The idea behind this is to transfer the first modal view controller back to the root view controller, and then immediately transfer the new modal view controller back to the screen.

If this is just a view that is different from the splash screen, you can instead of two view controllers have one view controller with logic that simply swaps one view for another depending on the URL entered and uses animation when exchanging between views.

+7
source

Source: https://habr.com/ru/post/1379699/


All Articles