简体   繁体   English

显示的弹出窗口没有覆盖整个屏幕 swift

[英]Pop up displayed is not covering the entire screen swift

在此处输入图片说明

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我是 iOS 开发的新手,我在屏幕上点击按钮时显示了弹出窗口,但它没有覆盖整个屏幕,显示弹出窗口的代码

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)

You need to add AutoLayout constraints.您需要添加 AutoLayout 约束。 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)

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 https://developer.apple.com/documentation/uikit/uiviewcontroller/1621380-presentviewcontroller?language=objc

and this和这个

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

to have better understating of what going on :)更好地了解正在发生的事情:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM