-1

I've following view configuration

Tab bar -> Nav controller -> View: Click on a button -> segue to-> Another view: Click on a button -> Popup view.

This modal view is on a different storyboard.

I want to present this model view in full screen. I've tried this solution mentioned on Presenting modal in iOS 13 fullscreen but it doesn't work. I've also tried few other solutions but the popup view is not showing over full screen, status bar is visible at the top.

How do I present modal view in a full screen?

let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)

guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
   print("PopUpViewController not found")
   return
}

popupVC.modalPresentationStyle = .fullScreen

self.present(popupVC, animated: true, completion: nil)
Raymond
  • 1,108
  • 13
  • 32

2 Answers2

4

You could try presenting with the navigation controller.

let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)

guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
   print("PopUpViewController not found")
   return
}

var navigationController = UINavigationController(rootViewController: popupVC)
navigationController.modalPresentationStyle = .fullScreen
self.present(navigationViewController, animated: true, completion: nil)

An alternative would be to use presentViewController but presentViewController will only present one viewController modally over the currently visible viewController whereas presenting with the navigationController will give the flexibility to push further components on top, providing a smoother navigation experience with go back to previous page kind of behaviour.

Deeksha Kaul
  • 264
  • 2
  • 7
0

Maybe try creating the view controller this way:

    let popOverVC = UIStoryboard(name: "yourBoard", bundle: nil).instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
    self.addChild(popOverVC)
    let lSs = UIScreen.main.bounds
    popOverVC.view.frame = CGRect(x: 0, y: 0, width: lSs.width, height: lSs.height)
    popOverVC.view.tag = tag
    self.view.addSubview(popOverVC.view)
    popOverVC.didMove(toParent: self)

Within the popup view controller class, add a method for animating its view in viewDidLoad.

Edit: I read your replies. The issue you are having is caused by not handling the status bar properly. Instead of trying to make this veiewcontroller fullscreen, simply hide the status bar How do I hide the status bar in a Swift iOS app? and bring it back when you want to see it again.

ekrenzin
  • 387
  • 2
  • 12
  • I'm aware of hiding status bar. If you say show a view in full screen doesn't that mean it should be above status bar too? Is status bar beyond the scope of "full screen"? – Raymond Oct 17 '19 at 16:19
  • yes, you can think of the status bar as 'beyond the scope of full screen'. It is possible so you can put backgrounds and whatnot behind the status bar without removing it. – ekrenzin Oct 17 '19 at 19:36
  • Ok then it's entirely different ball game now. – Raymond Oct 17 '19 at 21:32