当用户按下按钮时,我将ViewController称为弹出框。视图应具有黑色背景,alpha 为 0.5。但是视图显示为一秒钟,然后整个背景在没有 alpha 的情况下变黑。知道为什么吗?
这是我的弹出电话:
let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
popOver.modalPresentationStyle = .popover
self.present(popOver, animated: true, completion: nil)
我正在尝试使用以下代码在弹出窗口viewDidLoad()
函数中设置背景颜色:
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
对于该集合,modalPresentationStyle
overCurrentContext
而不是popover
。
let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
popOver.modalPresentationStyle = .overCurrentContext
self.present(popOver, animated: true)