问题
I wonder if its OK by iOS Human Interface Guidelines to style a UIView so it looks and acts like a navbar.
My problem is that I want to hide my current navbar once the user scrolls.
I have tried both self.navigationController?.setNavigationBarHidden(true, animated: true)
and navigationController?.hidesBarsOnSwipe = true
but the animation looks odd, once the navigation bar gets hidden I still have about 20px space under the status bar: You can look at my other question
So to make things easier, can I just init my view tih the navbar hidden and style my own and add the proper animation?
回答1:
Try this out :
extension YourViewController {
override func prefersStatusBarHidden() -> Bool {
return barsHidden // Custom property
}
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return .Slide
}
}
You have to update barsHidden somewhere in the code and call setNeedsStatusBarAppearanceUpdate() method.
来源:https://stackoverflow.com/questions/40175513/hide-navigation-bar-on-scroll