Popup UIViewController Popup UIViewController ios ios

Popup UIViewController


To make your view controller shown as a popup, you should set the following:

popupVC.modalPresentationStyle = .OverCurrentContextpopupVC.modalTransitionStyle = .CrossDissolve

You should also design your view controller's position, size to make it look like a popup.

Here is my popup that i did before.

enter image description here


At the parent controller:

let vc = ViewController()vc.modalPresentationStyle = .overCurrentContextvc.modalTransitionStyle = .crossDissolvepresent(vc, animated: true, completion: nil)

At the pop up controller, use this to enable showing the parent controller in the background:

self.definesPresentationContext = true

Don't forget to set a translucent background to your pop up controller.

-- Reference from: Presenting a popup view controller programmatically - Reddit --


Another simple solution, using EzPopup (https://github.com/huynguyencong/EzPopup). It's very simple with just a few lines of code:

// init YourViewControllerlet contentVC = ...// Init popup view controller with content is your content view controllerlet popupVC = PopupViewController(contentController: contentVC, popupWidth: 100, popupHeight: 200)// show it by call present(_ , animated:) method from a current UIViewControllerpresent(popupVC, animated: true)