I have a popup class for showing some message across my entire app. I have to init an instance and add it as a child of a currently appearing controller then show the popup view whenever I want:
func popMessage() {
let popup = MyPopup()
self.addChildViewController(popup)
self.view.addSubView(popup.view)
popup.didMoveToParentViewController(self)
popup.show()
}
Sometimes the current view controller is embedded in UINavigationController
or UITabBarController
.
In case of making my popup view show in whole screen size without being clipped by the navigation bar or tab bar, I have to add it as child of the navigation controller or tab bar controller. This is annoying when I decide to change controller hierarchy.
How can I make it easier like using an UIAlertViewController:
let popup = MyPopup()
popup.show()
or
self.presentViewController(popup)
Pop it anywhere and make it the only focus on screen without regarding which parent view controller the popup should have?