我的 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)
}
}