Home Forums iOS Development Show and dismiss ViewController modally

This topic contains 10 replies, has 2 voices, and was last updated by  DenisXaa 3 months, 1 week ago.

Viewing 10 posts - 1 through 10 (of 11 total)
  • Author
    Posts
  • #2705 Reply

    Malek
    Keymaster

    Moved here from http://sweettutos.com/forums/topic/switch-the-root-controller-with-an-animation/

    • This topic was modified 1 year, 10 months ago by  Malek.
    #2704 Reply

    Michele

    Hi 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.
    Michele

    #2708 Reply

    Malek
    Keymaster

    Hi Michele,

    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”):

    To dismiss the view controller (from the SecondViewController.swift class):

    • This reply was modified 1 year, 10 months ago by  Malek.
    #2712 Reply

    Michele

    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)
    NV2->VC-VC …

    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,

    Michele

    #2713 Reply

    Malek
    Keymaster

    Hey Michele,
    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)

    #2717 Reply

    Michele

    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?)

    Thanks,
    Michele

    #2718 Reply

    Malek
    Keymaster

    Hi Michele 🙂
    The following dismiss API will automatically perform a Top-to-Bottom transition as you want:

    Hope this help!
    Malek

    #2722 Reply

    Michele

    Hi Malek,
    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,
    Michele

    #2723 Reply

    Malek
    Keymaster

    Hi Michele,
    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:

    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):

    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.

    #6381 Reply

    MashaCkq

    Hi all! Recently I have been struggling with a lot of personal issues. Friends and doctors keep telling me I should consider taking medicine, so I may as well Contact and see how it goes. Problem is, I haven’t taken it for a while, and don’t wanna get back to it, we’ll see how it goes.

Viewing 10 posts - 1 through 10 (of 11 total)
Reply To: Show and dismiss ViewController modally
Your information: