首页 > 解决方案 > 弹出显示没有迅速覆盖整个屏幕

问题描述

在此处输入图像描述

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

标签: iosswift

解决方案


您可以简单地呈现一个:

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

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


推荐阅读