포스트

How to hide navigation bar when scrolling

In UINavigationController, there is a property called hidesBarsOnSwipe which hides its bars when scrolling or swipe down.

1
navigationController?.hidesBarsOnSwipe = true

We also need to set the view’s top anchor to superview’s top anchor. For example, there is a collection view inside a view controller. The collection view’s top anchor is related to Superview’s top anchor. If we don’t set it, we can’t show the navigation bar when scrolling or swipe up.

Collection view's top anchor is related to superview's top anchor.

Animated image that shows navigation bar is hidden when scrolled.

Reference:
Apple Developer Documentation

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.