繁体   English   中英

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

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

在此处输入图片说明

我是 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)

您需要添加 AutoLayout 约束。 这个片段应该可以帮助你。

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)

你可以简单地展示一个:

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)

我也推荐阅读这篇文章

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

和这个

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

更好地了解正在发生的事情:)

暂无
暂无

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

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