標籤:des style blog http color io os 使用 ar
你曾注意過Safari移動用戶端裡美輪美奐的導覽列縮放效果麼,以及那些tab bar是如何消失的嗎?
在iOS 8中,蘋果讓這種類型的互動變得非常容易,雖然在WWDC上示範了縮放導覽列效果,不過後來他們用隱藏導航的方式替代了這個想法,但tab bar不包括在內(我猜想他們後期會添加隱藏標籤欄的屬性)。
以下是iOS 8中非常酷的導航互動方式,可以讓使用者看到更多內容。
滾動頁面時隱藏Bar
如果你有一個Table View,僅需要將導航控制項的hidesBarsOnSwipe屬性設定為true就OK了。
class QuotesTableViewController: UITableViewController { override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) navigationController?.hidesBarsOnSwipe = true }}
注意導覽列的行為會影響到在你的導航堆棧裡所有的視圖控制項,所以如果你希望某一視圖控控制項的導航條不會跟著隱藏的話,你需要設定一下viewDidAppear。
點擊時隱藏
如果你的視圖並不像上面所示那樣的捲動的話,你可以試著將hidesBarsOnTap的屬性設定為true.
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,你可以在輸入鍵盤出現時將導覽列隱藏:
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.
其他特性
下面示範的是其他新的導航控制器屬性,你可以看一下:
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 }
轉自:http://www.cocoachina.com/ios/20140923/9729.html
不容錯過的iOS 8的導航互動