为什么后退按钮和视图的起始元素之间存在巨大的差距?
Why is there a huge big gap between the back button and the starting element of the view?
这是我在模拟器上的视图
我不明白这个巨大的差距是怎么来的。我的观点是这样开始的
NavigationView {
VStack {
Form {
Section(header: Text("Mandatory Fields")){
TextField("First name", text: $identifyingData.firstName)
.autocapitalization(.words)
.disableAutocorrection(true)
....
这是调用上面视图的代码
.toolbar {
ToolbarItem(placement: .confirmationAction){
NavigationLink(destination: MyView(myData: .constant(MyData.empty))){
Image(systemName: "plus")
}
}
}
在意识到您的推送视图也嵌入到 NavigationView
后,我能够重现您的问题。只需将推送的视图提取到 NavigationView 之外,问题就会得到解决。适合我。
根视图:
struct FirstTestView: View {
var body: some View {
NavigationView {
NavigationLink(destination: FormsView()) {
Text("Push me")
}
}
}
}
推送视图:
struct FormsView: View {
@State var txt = ""
var body: some View {
VStack {
Form {
Section(header: Text("Mandatory Fields")){
TextField("First name", text: $txt)
.autocapitalization(.words)
.disableAutocorrection(true)
}
}
}
.navigationBarTitleDisplayMode(.inline)
}
}
结果:
这是我在模拟器上的视图
我不明白这个巨大的差距是怎么来的。我的观点是这样开始的
NavigationView {
VStack {
Form {
Section(header: Text("Mandatory Fields")){
TextField("First name", text: $identifyingData.firstName)
.autocapitalization(.words)
.disableAutocorrection(true)
....
这是调用上面视图的代码
.toolbar {
ToolbarItem(placement: .confirmationAction){
NavigationLink(destination: MyView(myData: .constant(MyData.empty))){
Image(systemName: "plus")
}
}
}
在意识到您的推送视图也嵌入到 NavigationView
后,我能够重现您的问题。只需将推送的视图提取到 NavigationView 之外,问题就会得到解决。适合我。
根视图:
struct FirstTestView: View {
var body: some View {
NavigationView {
NavigationLink(destination: FormsView()) {
Text("Push me")
}
}
}
}
推送视图:
struct FormsView: View {
@State var txt = ""
var body: some View {
VStack {
Form {
Section(header: Text("Mandatory Fields")){
TextField("First name", text: $txt)
.autocapitalization(.words)
.disableAutocorrection(true)
}
}
}
.navigationBarTitleDisplayMode(.inline)
}
}
结果: