Pop up displayed is not covering the entire screen swift

786 Views Asked by At

enter image description here

I am new to iOS development, I have displayed popup on click on button on screen, but it is not covering entire screen, code to show popup

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController
self.addChild(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParent: self)
2

There are 2 best solutions below

0
mkowal87 On

You need to add AutoLayout constraints. This snippet should help you.

addChild(childViewController)
view.addSubview(childView)
childView.translatesAutoresizingMaskIntoConstraints = false
view.topAnchor.constraint(equalTo: childView.topAnchor).isActive = true
view.bottomAnchor.constraint(equalTo: childView.bottomAnchor).isActive = true
view.leftAnchor.constraint(equalTo: childView.leftAnchor).isActive = true
view.rightAnchor.constraint(equalTo: childView.rightAnchor).isActive = true
childViewController.didMove(toParent: self)
0
Alexey Lysenko On

you can simply present one over another:

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController
// This one makes popOverVC fullscreen. In some cases you would like to use `.overFullScreen` just test what fits your scenario better
popOverVC = .fullScreen
// if you need it without animation, just call with animated: false
self.present(popOverVC, animated: true, completion: nil)

Also I'll recommend to read this article

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621380-presentviewcontroller?language=objc

and this

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621355-modalpresentationstyle?language=objc

to have better understating of what going on :)