我当前的 viewController 是黑色的(根据我的要求,这应该是黑色的)。我将另一个 View Controller 作为弹出窗口呈现。 该 Controller 有一个默认 View ,我将其设置为清晰的颜色,在默认 View 顶部采用另一个 View ,其背景颜色为黑色,并将其 alpha 设置为 .6,并在其顶部采用背景为白色的 tableview。我的问题是弹出窗口显示正确但是因为我的源 View Controller View 的颜色是黑色所以我的弹出窗口颜色也显示了这个效果
最佳答案
Add this code snippet from where you want to lunch popup.
var helpView = UIStoryboard(name: "MainStoryboard", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as? YourViewControllerClass
let window = UIApplication.shared.keyWindow
helpView.view.backgroundColor = UIColor.init(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.6)
helpView.view.frame = (window?.frame)!
window?.addSubview(helpView.view)
window?.rootViewController?.addChildViewController(helpView)
helpView.didMove(toParentViewController: self)
Add this code snippet on the popup close button action.
self.view.removeFromSuperview()
self.removeFromParentViewController()
关于swift - 将 uiview Controller 显示为弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56865515/