Reputation: 1839
I use the following line of code to hide the status bar:
view.window?.windowLevel = UIWindowLevelStatusBar
What is surprising me is that this line of code does not work from within any of the "life cycle" methods of the view
: viewDidLoad()
, viewWillAppear(:)
. However, when I create a button and hook it up to an action method the code above works perfectly and hides the status bar behind the window. I want to be able to call view.window?.windowLevel = UIWindowLevelStatusBar
in viewDidLoad()
. Can anyone please help me understand why it does not work from within the mentioned view
"life cycle" methods?
Upvotes: 0
Views: 63
Reputation: 387
If you only wanted to hide status bar use:
[[UIApplication sharedApplication] setStatusBarHidden:YES]
Upvotes: 0
Reputation: 130200
Neither in viewDidLoad
nor viewWillAppear
the view controller is in the view hierarchy, therefore view.window
is nil
.
You might work around that by using viewDidAppear
or access the window using UIApplication.shared.delegate.window
instead.
In general it's not a good idea to change the level
of the main window though.
Upvotes: 1
Reputation: 1
Your ViewController will only be able to adjust the status bar if you set View controller-based status bar appearance
to YES in your info.plist. Otherwise it is set by global parameters in your plist or proj file.
Upvotes: 0