53
54

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【超簡単】【たった一行】UINavigationBarをスワイプで表示/非表示させる方法

Last updated at Posted at 2015-03-07

##この記事について

UINavigationBarを消す方法を調べていたところ、scrollViewにdelegateを設定する方法や、ライブラリを使う方法などがありましたが、新しい方法を見つけましたので共有します。

iOS8からUINavigationControllerに便利なプロパティが追加されたようです。

##方法

navigationController?.hidesBarsOnSwipe = true

これだけ

##詳細

他にも色々な挙動でUINavigationBarを制御できるようです

  • hidesBarsOnTap

/// 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.
@available(iOS 8.0, *)
public var hidesBarsOnTap: Bool
  • hidesBarsOnSwipe
/// 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.
@available(iOS 8.0, *)
public var hidesBarsOnSwipe: Bool
  • hidesBarsWhenVerticallyCompact
/// 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.
@available(iOS 8.0, *)
public var hidesBarsWhenVerticallyCompact: Bool
  • hidesBarsWhenKeyboardAppears
/// 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.
@available(iOS 8.0, *)
public var hidesBarsWhenKeyboardAppears: Bool
  • navigationBarHidden
public var navigationBarHidden: Bool
  • barHideOnTapGestureRecognizer
/// 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.
@available(iOS 8.0, *)
unowned(unsafe) public var barHideOnTapGestureRecognizer: UITapGestureRecognizer { get }
  • barHideOnSwipeGestureRecognizer
/// 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.
@available(iOS 8.0, *)
public var barHideOnSwipeGestureRecognizer: UIPanGestureRecognizer { get }

Hiding the Navigation Bar @ Apple公式ドキュメント - UINavigationController Class Reference

53
54
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
54

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?