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 true
, the 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.
Code:
navigationController?.hidesBarsOnTap = true
Remember to set this back to false
when you want to stop the behavior from happening.
SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.