我的ContentView中有一个NavigationLink,它显示带有一些文本的SecondView。当我在SecondView内应用.edgesIgnoringSafeArea修饰符时,文本超出了屏幕范围,仅当隐藏了NavigationBar时,这才发生在NavigationLink内部。
如果您也遇到这种情况,您是否也可以测试此代码?
struct ContentView: View {
@State var hiddenBar = false
var body: some View {
NavigationView {
NavigationLink(destination: SecondView(hiddenBar: $hiddenBar)) {
Text("Go to second View")
}
.onAppear {
self.hiddenBar = false
}
.navigationBarTitle("Title", displayMode: .inline)
.navigationBarHidden(hiddenBar)
}
}
}
struct SecondView: View {
@Binding var hiddenBar: Bool
var body: some View {
VStack {
Text("Text that goes outside of the safe area plus the amount of Navigation Bar height because it's hidden...You can see just this peace of text here")
Spacer()
}
.onAppear {
self.hiddenBar = true
}
.edgesIgnoringSafeArea(.top)
}
}