I have AuthViewController
that is presenting MainViewController
like so:
let mainVC = MainViewContoller()
mainVC.modalTransitionStyle = .CrossDissolve
authVC.presentViewController(mainVC, animated: true, completion: nil)
I want the AuthViewController
to hide the status bar, but the MainViewController
to show, like so:
AuthViewController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return .Fade
}
override func prefersStatusBarHidden() -> Bool {
return false
}
}
MainViewController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return .Fade
}
override func prefersStatusBarHidden() -> Bool {
return false
}
}
The status bar appears, however the preferredStatusBarUpdateAnimation()
override is ignored. The status bar appears with no animation.
I have only been able to get it to animate by setting prefersStatusBarHidden
on MainViewController
to true
until the viewDidAppear
, then calling this:
UIView.animateWithDuration(0.3) {
self.setNeedsStatusBarAppearanceUpdate()
}
I don't want to have to call this every time. What am I doing wrong?
been searching for a solution to this too. However it seems you got half the solution already. You have to set up the overrides for the variables, but best practice for me was to create a private variable pair for each of the overrides, and have each override return it's respective private var (see bellow). You'd then change up the private variables and call
setNeedsStatusBarAppearanceUpdate
.Plus, you need to set
View controller-based status bar appearance
in yourinfo.plist
toYES
. Otherwise, it will still rely on the legacyUIApplication.shared...
methods.Here's a snippet:
which I then could call in a function like so: (this is one of my examples, so disregard the custom function).
You end up having to tune every view controller, but it seems like it's what you want to do, so hope it helps!