Reputation: 2354
I've got a generic UIViewController in which I would like to hide the status bar. I've got more view controllers which should display the status bar, but this specific view controller should hide the status bar.
I've implemented the following methods in the UIViewController class:
override func viewDidLoad() {
super.viewDidLoad()
// FIXME: hide status bar
var prefersStatusBarHidden: Bool {
return true
}
setNeedsStatusBarAppearanceUpdate()
}
override func viewWillAppear(_ animated: Bool) {
UIApplication.shared.isStatusBarHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
UIApplication.shared.isStatusBarHidden = false
}
In my info.plist, I've set up the following setting:
The status bar does not hide when I navigate to that view controller and is still visible.
Upvotes: 2
Views: 7251
Reputation: 12343
In Swift 5
override var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
Upvotes: 0
Reputation: 6009
To turn off the status bar for some view controllers but not all, remove this info.plist entry if it exists OR set it to YES:
View controller-based status bar appearance = YES
Then add this line to each view controller that needs the status bar hidden
override var prefersStatusBarHidden: Bool { return true }
To turn off the status bar for the entire application, add this to info.plist:
View controller-based status bar appearance = NO
This will allow the "Hide status bar" to work as expected. Check the hide status bar located in the project's General settings under Deployment Info.
Upvotes: 1
Reputation: 1078
App Delegate swift 4.2
NotificationCenter.default.addObserver(self, selector: #selector(videoExitFullScreen), name:NSNotification.Name(rawValue: "UIWindowDidBecomeHiddenNotification") , object: nil)
@objc func videoExitFullScreen() {
UIApplication.shared.setStatusBarHidden(false, with: .none)
}
Upvotes: 0
Reputation: 97
UIApplication.shared.isStatusBarHidden = true
above this Setter for 'isStatusBarHidden
' was deprecated in iOS 9.0
so use below code it's working fine :)
override var prefersStatusBarHidden: Bool {
return true
}
Upvotes: 0
Reputation: 29
Add following line in your ViewController
extension UIViewController {
func prefersStatusBarHidden() -> Bool {
return true
}
}
Upvotes: -2
Reputation: 79636
override prefersStatusBarHidden
in your view controller:
override var prefersStatusBarHidden: Bool {
return true
}
Set a value No
for View Controller based status bar appearance
and then show/hide your status bar for specific view controller.
Here is result:
Upvotes: 8
Reputation: 8506
In view controller where you want to hide the status bar,
In the viewWillAppear
method, UIApplication.shared.isStatusBarHidden = true
,
In the viewWillDisAppear
method, UIApplication.shared.isStatusBarHidden = false
Upvotes: 1