struct ContentView: View {
@State var hideNavigationBar: Bool = false
var body: some View {
NavigationView {
ScrollView {
VStack {
Rectangle().fill(Color.red).frame(height: 50)
.onTapGesture(count: 1, perform: {
withAnimation {
self.hideNavigationBar.toggle()
}
})
VStack {
ForEach(1..<50) { index in
HStack {
Text("Sample Text")
Spacer()
}
}
}
}
}
.navigationBarTitle("Browse")
.navigationBarHidden(hideNavigationBar)
}
}
}
When you tap the red rectangle it snaps the navigation bar away. I thought withAnimation{}
would fix this, but it doesn't. In UIKit
you would do something like this navigationController?.setNavigationBarHidden(true, animated: true)
.
Tested in xCode 12 beta 6 and xCode 11.7
.animate()
view modifier to theScrollView
? (I'd suggest placing it beneath.navigationBarHidden(hideNavigationBar)
– Holophrastic