导航链接和滚动视图问题SwiftUI

时间:2019-12-16 14:36:44

标签: ios swift xcode scrollview swiftui

我对导航链接和SwiftUI有问题。导航栏消失,我的滚动视图上升。我已在以下链接的Facebook上上传了有关该问题的视频:the link of the video

enter image description here

这是我主要视图的代码:

    struct MainView: View {

    let date = Date()
    let calendar = Calendar.current


    static let formatter: DateFormatter = {


        let formatter = DateFormatter()

        formatter.dateStyle = .medium

        formatter.timeStyle = .short

        return formatter

    }()

    //MARK: Properties
    @ObservedObject var session = FirebaseSession()

    let user = Auth.auth().currentUser

    @State private var showModal = false

    var body: some View {
        NavigationView{
           // Group {

                ZStack {
                if session.session != nil {
                    ScrollView {
                        VStack{
                            ScrollView(.horizontal, showsIndicators: false){
                                HStack{
                                    NavigationLink(destination: RedactorView()) {
                                    RedactorListItem()
                                             }.buttonStyle(PlainButtonStyle())
                                     RedactorListItem()
                                     RedactorListItem()
                                     RedactorListItem()
                                     RedactorListItem()
                                     RedactorListItem()
                                }//.padding()
                            }
                            VStack(alignment: .leading, spacing: 5) {
                                HStack {
                                    Text("Les derniers médias")
                                    .font(.largeTitle)
                                    .bold()
                                        Spacer()
                                    Text("Voir plus >")
                                    .padding(8)
                                        .background(Color(UIColor.secondarySystemBackground))
                                    .clipShape(Capsule())
                                }.padding(.horizontal)
                            ScrollView(.horizontal, showsIndicators: false){
                                HStack{
                                    NavigationLink(destination: MotherView(viewRouter: ViewRouter())){
                                    MediaListRow()
                                        .frame(width: UIScreen.main.bounds.width/1.15)
                                        .scaledToFit()
                                    }.buttonStyle(PlainButtonStyle())
                                    MediaListRow()
                                        .frame(width: UIScreen.main.bounds.width/1.15)
                                        .scaledToFit()
                                    MediaListRow()
                                        .frame(width: UIScreen.main.bounds.width/1.15)
                                        .scaledToFit()
                                    MediaListRow()
                                        .frame(width: UIScreen.main.bounds.width/1.15)
                                        .scaledToFit()
                                    MediaListRow()
                                        .frame(width: UIScreen.main.bounds.width/1.15)
                                        .scaledToFit()


                                }
                                }

                                HStack {
                                    Text("Les derniers articles :")
                                        .font(.largeTitle)
                                        .bold()
                                        Spacer()
                                    Text("Voir plus >")
                                    .padding(8)
                                        .background(Color(UIColor.secondarySystemBackground))
                                    .clipShape(Capsule())

                                }.padding(.horizontal)

                                ArticleListRow()
                                ArticleListRow()
                                ArticleListRow()

                            }

                        }


                    .navigationBarTitle("WYN")
                    .navigationBarHidden(true)
                    }.navigationViewStyle(StackNavigationViewStyle()).padding(.top, 90)

                    ZStack{
                        VStack{
                            HStack{
                                VStack(alignment: .leading) {

                                VStack {
                                    VStack(alignment: .leading){

                                        HStack{
                                            Text("What You Need")
                                                .font(.system(.largeTitle, design: .serif))
                                                .bold()

                                            Spacer()




                                                Button(action: {
                                                   self.showModal.toggle()
                                                }) {
                                                    Image(systemName: "person.crop.circle.fill")
                                                    .font(.largeTitle)
                                                    .foregroundColor(.primary)
                                                }

                                            .sheet(isPresented: $showModal){
                                                SettingView(showModal: self.$showModal)
                                            }
                                        }

                                        Text("\(date, formatter : MainView.self.formatter)")
                                            .font(.callout)
                                            .bold()
                                            .foregroundColor(Color(UIColor.systemGray4))

                                    }

                                    /*
                                    Rectangle()
                                        .frame(height: 2)
                                        .cornerRadius(1)
                                        .foregroundColor(Color(UIColor.systemGray5))

                                   */

                                }
                                .padding(.horizontal)
                                .padding(.top, 20)

                                    }.background(Color(UIColor.systemBackground)).frame(minWidth: 0, maxWidth: .infinity).frame(height: 75)
                            }
                            Spacer()
                        }
                    }

                } else {
                    Authentification()
                }
            }
            .onAppear(perform: getUser)

            //}
            .navigationBarTitle("Menu Principal")
            .navigationBarHidden(true)
        }.navigationViewStyle(StackNavigationViewStyle())
    }

    //MARK: Functions
    func getUser() {
        session.listen()
    }

}

这是我的详细视图的代码:


import SwiftUI

struct RedactorView: View {
    var body: some View {
    //    NavigationView {
        ScrollView {
             VStack(alignment: .leading) {
                    HStack{
                        Image("P1")
                        .resizable()
                        .scaledToFill()
                        .frame(width: 115, height: 115)
                        .clipShape(Circle())

                            .padding(.trailing)
                        VStack(alignment: .leading){
                            Text("Prénom")
                                .font(.largeTitle)
                                .bold()
                            Text("Nom")
                                .font(.largeTitle)
                                .bold()
                            HStack {
                                VStack(alignment: .center){
                                    Text("10")
                                        .bold()
                                    Text("Articles")
                                        .foregroundColor(Color(UIColor.secondaryLabel))
                                }
                                VStack(alignment: .center){
                                    Text("5")
                                        .bold()
                                    Text("Medias")
                                        .foregroundColor(Color(UIColor.secondaryLabel))
                                }
                            }.padding(.top)
                        }
                        Spacer()
                    }.padding(.horizontal)
                    ScrollView(.horizontal, showsIndicators: false) {
                        HStack {
                            HStack{
                                Text("Email")

                                    .bold()
                                Image(systemName: "envelope.fill")
                                 //   .foregroundColor(Color(UIColor.systemBlue))
                            }.foregroundColor(Color(UIColor.systemBlue))
                                .padding(8)
                                .background(Color(UIColor.systemBackground))
                                .clipShape(Capsule())
                                .shadow(color: Color(UIColor.systemGray6), radius: 10)
                            HStack{
                                                   Text("Instagram")

                                                           .bold()
                                                           Image(systemName: "heart.fill")


                                                   }.foregroundColor(Color(hue: 0.93, saturation: 0.81, brightness: 0.84)).padding(8)
                                               .background(Color(UIColor.systemBackground))
                                               .clipShape(Capsule())
                                               .shadow(color: Color(UIColor.systemGray6), radius: 10)
                            HStack{
                                Text("Message")

                                    .bold()

                                Image(systemName: "message.fill")


                            }.foregroundColor(Color(UIColor.systemGreen))
                                .padding(8)
                                .background(Color(UIColor.systemBackground))
                                .clipShape(Capsule())
                                .shadow(color: Color(UIColor.systemGray6), radius: 10)
                            HStack{
                                Text("Téléphone")

                                .bold()
                                Image(systemName: "phone.fill")

                            }.foregroundColor(Color(UIColor.systemGreen)).padding(8)
                            .background(Color(UIColor.systemBackground))
                            .clipShape(Capsule())
                            .shadow(color: Color(UIColor.systemGray6), radius: 10)

                        }.padding()

                    }

                    VStack(alignment: .leading, spacing: 5) {
                        Text("Ses Medias :")
                            .font(.largeTitle)
                            .bold()
                            .padding(.leading)
                        ScrollView(.horizontal, showsIndicators: false){
                            HStack{

                                MediaListRow()
                                    .frame(width: UIScreen.main.bounds.width/1.15)
                                    .scaledToFit()
                                MediaListRow()
                                    .frame(width: UIScreen.main.bounds.width/1.15)
                                    .scaledToFit()
                                MediaListRow()
                                    .frame(width: UIScreen.main.bounds.width/1.15)
                                    .scaledToFit()
                                MediaListRow()
                                    .frame(width: UIScreen.main.bounds.width/1.15)
                                    .scaledToFit()
                                MediaListRow()
                                    .frame(width: UIScreen.main.bounds.width/1.15)
                                    .scaledToFit()

                            }
                        }
                        Text("Ses Articles :")
                            .font(.largeTitle)
                            .bold()
                            .padding(.leading)

                        ArticleListRow()
                        ArticleListRow()
                        ArticleListRow()
                    }
                }.navigationBarTitle("Redactor")

           }
       // }//.padding(.top, -20)
    }
}

我不知道该怎么解决,我希望它能正常打开,但找不到,并且所有滚动视图都相同。请帮我。

1 个答案:

答案 0 :(得分:0)

在navigationView上缺少.edgesIgnoringSafeArea(.top),可以为您提供safeArea防护。