问题描述
我想知道iOS人机界面指南是否可以对UIView进行样式设置,使其外观和行为类似于导航栏.
I wonder if its OK by iOS Human Interface Guidelines to style a UIView so it looks and acts like a navbar.
我的问题是,一旦用户滚动,我想隐藏当前的导航栏.我已经尝试了self.navigationController?.setNavigationBarHidden(true, animated: true)
和navigationController?.hidesBarsOnSwipe = true
,但是动画看起来很奇怪,一旦导航栏被隐藏,我在状态栏下仍然有大约20px的空间:您可以查看我的其他
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?
推荐答案
尝试一下:
extension YourViewController {
override func prefersStatusBarHidden() -> Bool {
return barsHidden // Custom property
}
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return .Slide
}
}
您必须在代码中的某个地方更新barHidden并调用setNeedsStatusBarAppearanceUpdate()方法.
You have to update barsHidden somewhere in the code and call setNeedsStatusBarAppearanceUpdate() method.
这篇关于在滚动条上隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!