Swift ViewController Background turns black with alpha

I call ViewController as a popover when the user clicks a button. The view should have a black background with alpha 0.5. But the view is displayed like this for a second than the whole background turns black without alpha. Any idea why?

Here is my popover call:

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

I am trying to set the background color in popovers viewDidLoad() with the following code:

 self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5) 
+5
source share
1 answer

To do this, set modalPresentationStyle to overCurrentContext instead of popover .

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

Source: https://habr.com/ru/post/1262284/


All Articles