In my case, I was looking for the status bar to hide/show on demand; instead of just when the view loads or disappears.
swift 3.x
//show status bar initially
var showStatusBar = true
//set the parameters
override var prefersStatusBarHidden: Bool {
if showStatusBar == true {
//does not prefer status bar hidden
print("does not prefer status bar hidden")
return false
} else {
//does prefer status bar hidden
print("does prefer status bar hidden")
return true
}
}
//ex: hide status bar and call parameter function again whenever you want
showStatusBar = false
setNeedsStatusBarAppearanceUpdate()