Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I spawn a pop over view controller programatically?

Tags:

ios

swift

My goal is to show a View Controller programmatically

Current View Controller

enter image description here

and then, if some event gets called or something, (API, or Websocket) I want to call these Views programmatically

enter image description here

But I want to call the last view Controller first and it is supposed to be on top of the first View controller

enter image description here

So technically the last View will have

Transition is Cross Dissolve
Presentation is Over Current Context

How would I do this?

like image 996
sinusGob Avatar asked Aug 18 '17 09:08

sinusGob


2 Answers

I think the best way for a reusable view is to create a xib file. Then you can create a singleton and call this view every time you want to show this modal view.

To ensure that your view does not overlap with anything, you must add it not to the current controller, but to AppDelegate window.

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window!.addSubview(yourModalView)
like image 117
Vlad Krupenko Avatar answered Oct 11 '22 14:10

Vlad Krupenko


As per your requirement, you can set a storyBoardID for your navigation controller.

On a particular event just instantiate the Navigation controller let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main) let myNavController = storyboard.instantiateViewController(withIdentifier: "MyStoryboardId") as? UINavigationController

then present or show this navigation controller

self.present(myNavController, animated: true, completion: nil)

On viewDidLoad() method of first view controller perform the segue to popupViewController.

Now the secondView will show above the first view controller. you can dismiss this view after using it.

like image 23
Febin Fathah Avatar answered Oct 11 '22 13:10

Febin Fathah