ios – How to show and hide multiple overlays independently in swift


Goal:

We want to present and hide multiple independent overlays if some condition is met or no longer met.
We need this in order to block user access to our app while preserving the position (current ViewController stack). (e.g. a popup “please enable your location services”)

At any point we want to be able to show a fullscreen view (i.e. ViewController) that blocks access, this could be done in different places for different views, having independent criteria for showing the blocking view. When either criteria is no longer met, we want to hide this view. Independently, if the other criteria is still met, the other view should still block the app.


Problem:

Now this cannot be done using:

navigationController.present(vc, animated: true)

since this will only be able to retain one view (ViewController) i.e. if both criteria are met, present will be called twice (discarding one viewcontroller), dismissing once will dismiss the viewcontroller, giving access to the app even though it should still be blocked.

A similar problem arises when using:

navigationController.pushViewController(vc, animated: true)

This time one would have only the option to pop the latest viewcontroller, if the other is popped (using popTo...) the latest is discarded. Therefore, this also is not a solution if either must be able to show / hide independently.


How can this be achieved? Preferably by only having a reference to a UINavigationController or by using some extension or singleton pattern to improve separation of concerns.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img