添加自定义弹出窗口不会';t填写全视图iOS,Swift
我已经创建了一个UIViewController并在storyboard中进行了设计,我想将其显示为另一个视图的弹出窗口。 我使用以下内容显示为弹出窗口:添加自定义弹出窗口不会';t填写全视图iOS,Swift,ios,swift,popup,Ios,Swift,Popup,我已经创建了一个UIViewController并在storyboard中进行了设计,我想将其显示为另一个视图的弹出窗口。 我使用以下内容显示为弹出窗口: guard let popupVC = UIStoryboard(name: "More", bundle: nil).instantiateViewController(withIdentifier: "LanguageSelectionViewController") as? LanguageSelectionViewControlle
guard let popupVC = UIStoryboard(name: "More", bundle: nil).instantiateViewController(withIdentifier: "LanguageSelectionViewController") as? LanguageSelectionViewController else{
fatalError("Unexpected destination VC")
}
self.addChildViewController(popupVC)
popupVC.view.frame = self.tableView.frame
print("POPUP Frame VIEW -- \(popupVC.view.frame)")
print("SElF VIEW -- \(self.tableView.frame)")
popupVC.view.frame = self.tableView.frame
print("POPUP Frame VIEW -- \(popupVC.view.frame)")
print("SElF VIEW -- \(self.view.frame)")
popupVC.modalPresentationStyle = .currentContext
popupVC.modalTransitionStyle = .crossDissolve
popupVC.view.bindFrameToSuperviewBounds()
self.view.addSubview(popupVC.view)
popupVC.didMove(toParentViewController: self)
它工作正常,但在我的设备上,弹出视图并没有填满屏幕的一半空间
您需要做的第一件事是单击弹出窗口(故事板或xib),并将其设置为背景色
。清除颜色
然后把它放在中间。喜欢
popupVC.center=self.view.center
这只是一个指南,您可以相应地更改和设置名称。但是我的问题是,为什么您要使用故事板
为什么不创建Xib或View
希望它能达到你的目的 您是否尝试过使用present()函数?大概是这样的:
let popupVC = PopupViewController()
popupVC.modalPresentationStyle = .overFullScreen
popupVC.modalTransitionStyle = .crossDissolve
self.present(popupVC, animated: true, completion: nil)
我发现在自己的xib文件中设计视图控制器更容易,而且它允许像我的示例中那样进行初始化,而不必在代码中使用情节提要,但这是个人偏好。
如果仍然不起作用,请检查弹出窗口背景的布局约束是否正确,以便它实际填充其父窗口。您需要交换这两行:
self.view.addSubview(popupVC.view)
popupVC.view.bindFrameToSuperviewBounds()
如果视图尚未添加到superview中,则无法将视图绑定到其superview。不起作用,它甚至没有加载视图控制器。谢谢,这对我来说很有效,但我使用标识符启动了ViewController。初始化确实是个人偏好。很高兴我能帮忙。