Hide navigation bar on scroll

丶灬走出姿态 提交于 2019-12-13 23:41:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!