以下是iOS 8中非常酷的導航交互方式,可以讓用戶看到更多內容。
滾動頁面時隱藏Bar
如果你有一個Table View,僅需要將導航控件的hidesBarsOnSwipe屬性設置爲true就OK了。
1
2
3
4
5
6
7
8
|
class QuotesTableViewController: UITableViewController { override func viewDidAppear(animated: Bool) { super .viewDidAppear(animated) navigationController?.hidesBarsOnSwipe = true } } |
注意導航欄的行爲會影響到在你的導航堆棧裏所有的視圖控件,所以如果你希望某一視圖控控件的導航條不會跟着隱藏的話,你需要設置一下viewDidAppear。
點擊時隱藏
如果你的視圖並不像上面所示那樣的捲動的話,你可以試着將hidesBarsOnTap的屬性設置爲true.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
class QuoteImageViewController: UIViewController { override func viewDidAppear(animated: Bool) { super .viewDidAppear(animated) // 將hidesBarsOnSwift設置爲false // 在此後的這個條件下它不會有任何效果 // 不過在上一個VC中它被設置成了true navigationController?.hidesBarsOnSwipe = false // setting hidesBarsOnTap to true navigationController?.hidesBarsOnTap = true } } |
請注意,如果你之前在導航棧中某個視圖控件裏設置過hidesBarOnSwipe,你需要再次將其賦值爲false以避免這個視圖會發生像其他的視圖那樣的行爲。同樣的,如果對於Table View也曾有過設置,那你仍需要重新將navigationController?.hidesBarsOnTap設爲false避免出錯。
展示鍵盤輸入時隱藏
如上圖,使用導航控件的新特性hidesBarsWhenKeyboardAppears,你可以在輸入鍵盤出現時將導航欄隱藏:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
class CreateQuoteTableViewController: UITableViewController { override func viewDidAppear(animated: Bool) { super .viewDidAppear(animated) navigationController?.hidesBarsOnSwipe = false // 這個例子恰到好處的結合了hidesBarsOnTap和hidesBarsWhenKeyboardAppears兩個特性 // 這樣用戶可以輕鬆的喚回導航欄並保存 navigationController?.hidesBarsOnTap = true navigationController?.hidesBarsWhenKeyboardAppears = true } } |
爲了確保用戶在使用時可以輕易的喚出隱藏的導航欄,你應該在需要的時候將hidesBarsOnTap或者hidesBarsOnSwipe設置爲true.
其他特性
下面演示的是其他新的導航控制器屬性,你可以看一下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
class UINavigationController : UIViewController { //... truncated /// When the keyboard appears, the navigation controller's navigationBar toolbar will be hidden. The bars will remain hidden when the keyboard dismisses, but a tap in the content area will show them. @availability(iOS, introduced=8.0) var hidesBarsWhenKeyboardAppears: Bool /// When the user swipes, the navigation controller's navigationBar & toolbar will be hidden (on a swipe up) or shown (on a swipe down). The toolbar only participates if it has items. @availability(iOS, introduced=8.0) var hidesBarsOnSwipe: Bool /// The gesture recognizer that triggers if the bars will hide or show due to a swipe. Do not change the delegate or attempt to replace this gesture by overriding this method. @availability(iOS, introduced=8.0) var barHideOnSwipeGestureRecognizer: UIPanGestureRecognizer { get } /// When the UINavigationController's vertical size class is compact, hide the UINavigationBar and UIToolbar. Unhandled taps in the regions that would normally be occupied by these bars will reveal the bars. @availability(iOS, introduced=8.0) var hidesBarsWhenVerticallyCompact: Bool /// When the user taps, the navigation controller's navigationBar & toolbar will be hidden or shown, depending on the hidden state of the navigationBar. The toolbar will only be shown if it has items to display. @availability(iOS, introduced=8.0) var hidesBarsOnTap: Bool /// The gesture recognizer used to recognize if the bars will hide or show due to a tap in content. Do not change the delegate or attempt to replace this gesture by overriding this method. @availability(iOS, introduced=8.0) unowned(unsafe) var barHideOnTapGestureRecognizer: UITapGestureRecognizer { get } }
|