SwiftUI show/hide title issues with NavigationBar
Below is a possible approach to hide navigation bar in root view and show in child subviews. The only needed modifications is in root view.
Tested with Xcode 11.4 / iOS 13.4
Here is a root only, child sub-views are regular and do not require special code for this case. See important notes inline.
struct RootNavigationView: View {
@State private var hideBar = true // << track hide state, and default
var body: some View {
NavigationView {
VStack {
Text("I'm ROOT")
Divider()
NavigationLink("Goto Child", destination: NextChildView(index: 1))
.simultaneousGesture(TapGesture().onEnded {
self.hideBar = false // << show, here to be smooth !!
})
}
.navigationBarHidden(hideBar)
// .navigationBarTitle("Back to Root") // << optional
.onAppear {
self.hideBar = true // << hide on back
}
}
}
}
SwiftUI Navigation Bar Title
It should be inside NavigationView
, like
struct ContentView: View {
var body: some View {
NavigationView {
Form {
...
}
.navigationBarTitle(Text("WeSplit")) // << here !!
}
}
}
Navigation Bar hide is not working in SwiftUI
NOTE: (For some reason it works in some cases) SwiftUI
requires that you need to .navigationBarTitle
for .navigationBarHidden
to work properly.
NavigationView {
ScrollView() {
......
}.
.navigationBarTitle("") //this must be empty
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
}
Related Topics
Apple Llvm 6.0 Error: Clang Failed with Exit Code -1
iPhone Storage in Tmp Directory
Create Singleton of a Viewcontroller in Swift 3
Locationmanager:Didenterregion Not Called When a Beacon Is Detected
How to Make Nsurlsession Post Request in Swift
When to Use a Colon with a @Selector
How to Decode Aac Audio Buffer to Pcm Buffer in iOS
How to Do Weak Linking in Swift
Alamofire with a Self-Signed Certificate/Servertrustpolicy
Find Uialertview Without Having Reference to It iOS 7
How to Get Memory Usage in Swift
Setkeepalivetimeout iOS Behavior, Exceeded 15 Wakes in 300 Sec
How to Deserialize an Escaped JSON String with Nsjsonserialization
Go VS. Return Button in iOS Keyboard for HTML Input Forms
Memory Leak When Using Nsurlsession.Downloadtaskwithurl