Swift version: 5.1
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.
SPONSORED Why the top iOS apps rely on Instabug for crash reporting. Crash reporting + Bug reporting + Customizable in-app surveys all in one SDK. Know which line of code caused the crash along with network logs, repro steps, and the session profiler to identify and resolve severe crashes quickly. See more detailed features comparison and try Instabug for free here.
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.