I am trying to hide status bar in one of my UIViewControllers (Swift 4).
Firstly, I set View controller-based status bar appearance to
Although some implementations are cleaner such as:
UIApplication.shared.isStatusBarHidden = true
There are some weird clipping animations during transitions. Although more verbose, I prefer @MachTurtle's solution:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
if let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as? UIView{
statusBar.isHidden = true
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar.isHidden = false
}
Try it out, works great for me.