In SwiftUI with attached code when i set navigationBarBackButtonHidden
to true, the NavigationStack's navigation bar always pushes in when I dismiss the detail view. Since it's a zoom transition, I want the navigation bar to stay and not animate. How do i solve this?
import SwiftUI
struct ContentView: View {
@Namespace private var namespace
var body: some View {
NavigationStack {
NavigationLink {
DetailView()
// here is the issue: if I set it to true, it will have that default push animation when dismissed, which is inconsistent with the zoom animation.
.navigationBarBackButtonHidden(false)
.navigationTransition(.zoom(sourceID: "world", in: namespace))
} label: {
Image(systemName: "globe")
.matchedTransitionSource(id: "world", in: namespace)
}
.navigationTitle("Main")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .primaryAction){
Button {
print("noop")
} label: {
Label("Toggle", systemImage: "rectangle.grid.1x2")
}
}
}
}
}
}
struct DetailView: View {
var body: some View {
ZStack{
Color.indigo
Text("body here")
}.ignoresSafeArea()
}
}
#Preview {
ContentView()
}
In SwiftUI with attached code when i set navigationBarBackButtonHidden
to true, the NavigationStack's navigation bar always pushes in when I dismiss the detail view. Since it's a zoom transition, I want the navigation bar to stay and not animate. How do i solve this?
import SwiftUI
struct ContentView: View {
@Namespace private var namespace
var body: some View {
NavigationStack {
NavigationLink {
DetailView()
// here is the issue: if I set it to true, it will have that default push animation when dismissed, which is inconsistent with the zoom animation.
.navigationBarBackButtonHidden(false)
.navigationTransition(.zoom(sourceID: "world", in: namespace))
} label: {
Image(systemName: "globe")
.matchedTransitionSource(id: "world", in: namespace)
}
.navigationTitle("Main")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .primaryAction){
Button {
print("noop")
} label: {
Label("Toggle", systemImage: "rectangle.grid.1x2")
}
}
}
}
}
}
struct DetailView: View {
var body: some View {
ZStack{
Color.indigo
Text("body here")
}.ignoresSafeArea()
}
}
#Preview {
ContentView()
}
Share
Improve this question
edited Mar 27 at 15:04
Benzy Neez
23.3k3 gold badges15 silver badges44 bronze badges
asked Mar 27 at 5:57
randomorrandomor
5,6855 gold badges49 silver badges70 bronze badges
1
|
2 Answers
Reset to default 1The animation seems to be associated with the navigation bar being removed, because there is no content.
The workaround you showed in your answer is retaining some content, so the navigation bar is not removed.
You could also try setting a navigation title:
DetailView()
.navigationBarBackButtonHidden(true)
.navigationTransition(.zoom(sourceID: "world", in: namespace))
.navigationTitle("Detail") //
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744109952a4558905.html
body here
view? – sonle Commented Mar 27 at 6:41