Search code examples
iosswiftuiviewcontrollerpresentviewcontroller

How to simultaneously present two view controllers?


My goal is to present a view controller without dismissing directly to its presentingViewController.

To make it more clear, consider the following example:

Referring to this storyboard:

enter image description here

Assuming that the first black view controller is the first (initial) one, it should present the third white view controller; The issue is the white view controller should dismisses to the second orange view controller but not the black one, so it should behave like:

  • Black VC Presents White VC.
  • White VC Dismisses to Orange VC.
  • Orange VC Dismisses to Black VC.

How to apply such a behavior?

Remark: There is no navigation controller, it should be present/dismiss, not push/pop.


Solution

  • This could be achieved by letting the first black view controller to present the second orange view controller and then the orange view controller should present the third white view controller.

    But this arises an issue which is: the end-user will clearly notice that there are two view controllers have been sequentially presented. For solving this, you will need to do a pretty simple trick which is to take a screenshot from the first view controller and passing it to the second view controller to display it while presenting the third view controller.

    You can check this repository to see how it is exactly could be done (Swift 3).

    The final output would be:

    enter image description here