.edgesIgnoringSafeArea无法正常工作

时间:2020-05-12 17:23:37

标签: swift swiftui navigationbar navigationlink

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

0 个答案:

没有答案