简体   繁体   中英

How to set the system background color below presented view controllers in ios 13

See the pic below, i presented a viewcontroller in my app, here comes 3 layers on screen:

  1. Black, provided by system
  2. My app, the presenting view controller, white
  3. My app, the presented view controller, white

My question is, shouldn't the first layer be a blurred screen shot of a previously running app, why it's black? can i set the color?

截屏


Edit: it turns out the first layer is not provided by system, but simply app's key window background! see my answer below

I managed to solve it by setting the key window background color, eg:

// inside appDelegate's didFinishLaunchingWithOptions
// The first layer will be white now
window?.backgroundColor = UIColor.white

In the viewWillAppear of the root view controller, you need to reset background color of it by put the code bellow:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.view.backgroundColor = .white
}

In put this at where you push the new view controller:

self.navigationController?.pushViewController(anotherVC, completion: {
            self.view.backgroundColor = .black
        })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM