Swift version: 5.6
As of iOS 8.0 it's easy to make a navigation bar automatically hide when the user taps the screen, but only when it's part of a
UINavigationController. When set to
hidesBarsOnTap property of a navigation controller automatically adds a tap gesture recognizer to your view to handle hiding (and showing) the navigation bar as needed.
navigationController?.hidesBarsOnTap = true
Remember to set this back to
false when you want to stop the behavior from happening.
SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Available from iOS 8.0 – see Hacking with Swift tutorial 1
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.