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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…