iOS 8 添加了一个 super 酷炫的新功能:在用户滚动时隐藏导航栏。
这在 viewDidload
中有一行:
navigationController?.hidesBarsOnSwipe = true
很酷,不是吗?
但是现在有个小问题:当导航栏隐藏的时候,状态栏还在,并且和内容重叠,很丑。
导航栏隐藏的时候应该怎么做才能让它隐藏起来?
最佳答案
在 UIViewController 上覆盖以下方法:
extension MyViewController {
override func prefersStatusBarHidden() -> Bool {
return barsHidden // this is a custom property
}
// Override only if you want a different animation than the default
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .slide
}
}
在代码的某处更新barsHidden
并调用
setNeedsStatusBarAppearanceUpdate()
关于ios - 滚动时隐藏状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26197260/