With animations:
- Solution 1:
class ViewController: UIViewController {
var hideStatusBar = false
@IBAction func buttonTapped(button: UIButton) {
hideStatusBar = !hideStatusBar
UIView.animateWithDuration(0.25) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
}
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return .Fade
}
override func prefersStatusBarHidden() -> Bool {
return hideStatusBar
}
}
- Solution 2:
@IBAction fun buttonTapped(button: UIButton) {
UIApplication.shared.setStatusBarHidden(false, withAnimation: .Fade)
}
But this was deprecated on iOS 9 and later :[
What should I do if: "View controller-based status bar appearance" = NO
UIApplication.shared.statusBarHidden = false
But this solution without animation :[