I want to hide statusBar
when I show a view
in screen.
func showView() {
if let keyWindow = UIApplication.shared.keyWindow{
let view = UIView(frame: keyWindow.frame)
view.backgroundColor = UIColor.black
keyWindow.addSubview(view)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
view.frame = keyWindow.frame
}) { (completedAnimnation) in
//hide status bar when view is showed
UIApplication.shared.isStatusBarHidden = true
}
}
}
This is the code that I show the view and I try to hide statusBar using : UIApplication.shared.isStatusBarHidden = true
. and also UIApplication.shared.setStatusBarHidden(true, with: .fade)
but none of these are working. Also can not override prefersStatusBarHidden
because I am on a UIView
class.
override var prefersStatusBarHidden: Bool {
return true
}
Note: Please, do not mark as duplicate because I have seen all other answers but none of them are working.I don't want to hide for all application, only when It shows the view.
My suggestion would be to create a variable:
Set it to true when your desired UIView appears, and false when it disappears.
Alternatively, just use a ViewController, and present the view from there -
step 1: In Info.plist file Click the plus button to add new key
View controller-based status bar appearance
Set the VALUE toNO
step 2: For hide in a single screen
step 3: For hide in entire app
AppDelegate.swift