簡體   English   中英

導航鏈接和滾動視圖問題 SwiftUI

[英]Navigation link and scroll view issue SwiftUI

我的導航鏈接和 SwiftUI 有問題。 導航欄消失,我的滾動視圖上升。 我已經在 Facebook 上上傳了該問題的視頻鏈接: 視頻鏈接

在此處輸入圖片說明

這是我的主視圖的代碼:

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

我不知道這個問題的解決方案是什么我希望它可以正常打開但它沒有找到,而且我對所有滾動視圖都有相同的解決方案。 請幫我。

它在 navigationView 上缺少.edgesIgnoringSafeArea(.top) ,它可以為您提供安全區域保護。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM