迅速ViewController背景变黑与阿尔法

时间:2017-01-04 11:22:25

标签: ios swift uiviewcontroller swift3 uibackgroundcolor

当用户按下按钮时,我将ViewController称为popover。视图应具有alpha 0.5的黑色背景。 但是视图显示为一秒钟,而不是整个背景变为黑色而没有alpha。知道为什么吗?

这就是我的popover电话:

let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
    popOver.modalPresentationStyle = .popover
    self.present(popOver, animated: true, completion: nil)

我正在尝试使用以下代码在popovers viewDidLoad()函数中设置背景颜色:

self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)

1 个答案:

答案 0 :(得分:5)

对于该集modalPresentationStyleoverCurrentContext而不是popover

let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
popOver.modalPresentationStyle = .overCurrentContext
self.present(popOver, animated: true)