导航后退按钮出现在无法单击的区域中的问题

时间:2020-03-01 00:36:17

标签: navigation swiftui

我正在尝试通过NavigationLink单击列表以导航到视图。

下面是我的详细视图的代码。

问题是后退按钮始终位于详细信息视图的顶部,并且用户无法单击,如代码下方的屏幕快照所示?我该如何解决?

struct ViewDetails: View {

    @EnvironmentObject var displayDetails: DisplayDetails

    var body: some View { 

        ScrollView {

            GeometryReader { geometry in

                ZStack {

                    if geometry.frame(in: .global).minY <= 0 {

                        Image("header")
                            .resizable()
                            .aspectRatio(contentMode: .fill)
                            .frame(width: geometry.size.width, height: geometry.size.height)
                            .offset(y: geometry.frame(in: .global).minY/9)
                            .clipped()

                    } else {

                        Image("header")
                            .resizable()
                            .aspectRatio(contentMode: .fill)
                            .frame(width: geometry.size.width, height: geometry.size.height + geometry.frame(in: .global).minY)
                            .clipped()
                            .offset(y: -geometry.frame(in: .global).minY)

                     }

                }   

            }.frame(height: 400)

            VStack(alignment: .leading) {

                HStack {

                    Image("author")
                        .resizable()
                        .aspectRatio(contentMode: .fill)
                        .frame(width: 60, height: 60)
                        .clipped()
                        .cornerRadius(10)

                    VStack(alignment: .leading) {

                        Text("Article by")
                            .font(.custom("AvenirNext-Regular", size: 15))
                            .foregroundColor(.gray)

                        Text("John Doe")
                            .font(.custom("AvenirNext-Demibold", size: 15))

                    }

                }.padding(.top, 20)

                Text("Lorem ipsum dolor sit amet")
                    .font(.custom("AvenirNext-Bold", size: 30))
                    .lineLimit(nil)
                    .padding(.top, 10)

                Text("3 min read • 22. November 2019")
                    .font(.custom("AvenirNext-Regular", size: 15))
                    .foregroundColor(.gray)
                    .padding(.top, 10)

                Text(articleContent)
                    .font(.custom("AvenirNext-Regular", size: 20))
                    .lineLimit(nil)
                    .padding(.top, 30)

            }
            .frame(width: 350)

        }
        .edgesIgnoringSafeArea(.top)

            .onAppear(perform: {

                self.displayDetails.showFullScreen.toggle()

            })

    }

}

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以设置导航栏displayMode

.navigationBarTitle(Text("Painting"),displayMode: .inline)
struct ContentView: View {
    var body: some View {
        NavigationView{
            VStack{
            //Text("testme")
            NavigationLink(destination: p200301navi()){
                Text("testme")
            }
            NavigationLink(destination: p200301nav_solution()){
                          Text("testme2")
                      }
            .navigationBarTitle(Text("Painting"),displayMode: .inline)
            }
        }
    }
}