Austin Whitelaw
Austin Whitelaw

Reputation: 107

Background color of view changes after view appears?

Okay so I set the background of my login screen to a certain color. I'm using firebase and when it doesn't detect an authentication, it instantiates the login view controller and presents it.

When it first shows up, it is the correct color, but then it gets darker right away. It kinda seems like the alpha goes back to normal 100%.

But if I use the same 2 lines of code on a logout button(in a tableview), the view comes up the correct color and doesn't change.

I can provide more info if needed. Thanks.

if(FIRAuth.auth()?.currentUser == nil) {
            let vc = self.storyboard?.instantiateViewController(withIdentifier: "firebaseLoginViewController")
            self.navigationController?.present(vc!, animated: true, completion: nil)
        }

 switch(indexPath.row) {
        case 5:
            let vc = self.storyboard?.instantiateViewController(withIdentifier: "firebaseLoginViewController")
            self.navigationController?.present(vc!, animated: true, completion: nil)
        }

Upvotes: 1

Views: 325

Answers (1)

Ryan Poolos
Ryan Poolos

Reputation: 18551

So when you present a view, the view behind it is removed after your view fills the screen. If your view has a semi transparent background color, then you'll notice when the other view is removed and the black window shows through.

You can fix this two ways. The first is obviously to use an alpha of 100% for your background color. However if you're looking for the semi transparent look on purpose, then you can see your modalPresentationStyle. There are several options for in your case I think the best would be .overFullScreen

Set it something like this before you present your viewController with a semi transparent background.

self.navigationController?.modalPresentationStyle = .overFullScreen

Upvotes: 1

Related Questions