iOS Programming Cookbook
上QQ阅读APP看书,第一时间看更新

Hiding navigation bar

  • You can at any time hide or show the navigation bar based on any logic you have in your app by calling:
     self.navigationController?.setNavigationBarHidden(true, animated: true) 

Passing true to the preceding function hides the bar, and passing false will show the bar. Also, you can specify whether you want to do it with animation or not.

  • UINavigationController has another awesome property called hidesBarsOnSwipe when you set it to true. The navigation bar will be hidden automatically when you swipe up a table view or a scroll view. Also, when you swipe down, it will be shown again. This feature is very nice, as it saves a lot of space for the user while scrolling a list of data to see as much data as possible on screen. Let's give it a shot; from our preceding example, open MasterViewController and add this line of code in the viewDidLoad function:
     self.navigationController?.hidesBarsOnSwipe = true 
  • Then, build and run; you will note the bar hides or shows while scrolling: