February 10, 2016 at 6:48 am #2705
February 10, 2016 at 6:48 am #2704
- This topic was modified 1 year, 4 months ago by Malek.
thanks a lot for sharing.
I’m a newbie swift coder so just a question.
How can I set a new rootViewController and dismiss modally the first one (animation from the top to the bottom?)
Thank you very much.
MicheleFebruary 10, 2016 at 12:01 pm #2708
Sure, it’s easy to show/dismiss view controllers, the animation you are looking for is the modal presentation.
Show view controller modally (Assuming the Storyboard ID is “SecondVCID”):1234let storyboard = UIStoryboard(name: "Main", bundle: nil)let vC = storyboard.instantiateViewControllerWithIdentifier("SecondVCID") as! SecondViewControllerself.presentViewController(vC, animated: true, completion: nil)
To dismiss the view controller (from the SecondViewController.swift class):12self.dismissViewControllerAnimated(true, completion: nil)
February 10, 2016 at 12:41 pm #2712
- This reply was modified 1 year, 4 months ago by Malek.
Hi Malek and thank you for your answer.
Unfortunally your suggestion doesn’t work out for me.
The two ViewControllers are not in the same stack, there are no segue that link the two VC and there are different Navigation controller.
NV1->VC->VC->VC(exit and set as rootController NV2)
I have 2 NV and I would to exit from a certain VC in the first stream and set the new rootNavigationController with the second NV2 with a smooth transition, if I can in a “dismiss modal” like style.
Thank you again,
MicheleFebruary 10, 2016 at 12:48 pm #2713
Since a navigation controller is a UIViewController subclass , then in order to move from NV1 to NV2 stack, you can set it as the root of the window with a modal animation:
appDelegate.window?.rootViewController?.presentViewController(NV2, animated: true, completion: nil)February 10, 2016 at 10:00 pm #2717
Thank you for your answer Malek.
Is it possible to use the inverse transition?
(I mean a flow from the top to the bottom like a dismiss and not from the bottom to the top?)
MicheleFebruary 10, 2016 at 10:02 pm #2718
Hi Michele 🙂
The following dismiss API will automatically perform a Top-to-Bottom transition as you want:12self.dismissViewControllerAnimated(true, completion: nil)
Hope this help!
MalekFebruary 11, 2016 at 4:21 pm #2722
unfortunally my VCs arent binded with segue so dismissVC doesn’t work…
I want to move setting up the rootViewController.
But the kind of animation a want is like the “dismiss”.
I’m struggling hard with this!
Thx a lot,
MicheleFebruary 11, 2016 at 5:05 pm #2723
You don’t need segues, you just need a storyboard ID. For example, you got 2 navigation controllers. The second nav controller storyboard ID is “NavCon2”. Here is how to show/dismiss it:
In the first navigation controller root class:123let storyboard = UIStoryboard(name: "Main", bundle: nil)let navController2 = storyboard.instantiateViewControllerWithIdentifier("NavCon2") as! UINavigationControllerpresentViewController(navController2, animated: true, completion: nil)
Now to dismiss the second navigation controller stack and go back to the first navigation stack you just do the following (in the root class of the second navigation controller stack):12dismissViewControllerAnimated(true, completion: nil)
Hope this helps!
Keep me updated, If you still have some issues, let me know and I will prepare a quick sample project to assist you further.