如何在swiftui中使用自定义后退按钮导航多个屏幕

时间:2021-05-03 07:37:38

标签: swift swiftui swiftui-list swiftui-navigationlink swiftui-navigationview

    NavigationView{
            VStack (spacing: -3){
                UserImage()
                Spacer()
                VStack(spacing:50){
                    Version()
                    VStack( spacing:25){
                        VStack(alignment: .leading, spacing:10){
                            TextField("Username", text:$username)
                                .font(Font.custom("Quicksand-SemiBold",size: 16))
                            Line()
                            
                        }
                        .padding([.leading, .trailing])
                        
                        VStack(alignment: .leading, spacing:10){
                            SecureField("Password", text:$password)
                                .font(Font.custom("Quicksand-SemiBold",size: 16))
                            Line()
                            
                        }
                        .padding([.leading, .trailing])
                        //                        NavigationLink(destination: HomeScreen(), tag: 1, selection: $selection) {
                        
                        Button(action: {print("Button Tapped")}){
                            SigninButtonContent()
                        }
                        //                        }
                        
                        HStack(spacing: 5){
                            Text("If you are new to AT Broadband")
                                .font(.subheadline)
                                .fontWeight(.regular)
                                .frame(width: 225)
                            
                            Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
                                TapHere()
                                
                            })
                        }
                        
                        Spacer()
                    }
                    .padding(.horizontal, 50)
                    
                }
                //Suzhiyam Card
                VStack{
                    HStack{
                        
                        CardView()
                        Spacer()
                    }
                    .padding(.bottom)
                    
                }
                
            }
            .navigationBarHidden(true)
        
    }
}

}

struct SigninButtonContent: View {
let login = HomeScreen()

var body: some View {
    HStack{
        NavigationLink(destination: HomeScreen()) {
            Text("SIGN IN")
                .font(.headline)
                .foregroundColor(Color.white)
                .padding()
                .frame(width: 100.0, height: 40.0)
                .background(/*@START_MENU_TOKEN@*//*@PLACEHOLDER=View@*/Color(red: 0.931, green: 0.213, blue: 0.228)/*@END_MENU_TOKEN@*/)
                .cornerRadius(35.0)
                .shadow(radius: 2,x:0,y: 3 )
        }
    }
}

}

这是我的登录屏幕代码,我对屏幕的 NavigationView 有一些疑问。 我有自定义后退按钮要使用,所以我使用

.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)

后退按钮仍然没有用。This is my login screen, After clicking Sign In button it Navigated to Home Screen

struct HomeScreen: View {
var body: some View {
    NavigationView{
        ScrollView{
            ZStack{
                lightGreyColor
                    .edgesIgnoringSafeArea(.all)
                VStack{
                    ZStack{
                        VStack(spacing: -90){
                            Image("OnePlus-6")
                                .resizable()
                                .aspectRatio(CGSize(width: 19, height: 9), contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/)
                                .frame(width: 340, height: 190)
                                .edgesIgnoringSafeArea(.top)
                                .overlay(RectangleTest())
                            VStack{
                                PlanCard()
                            }
                        }
                    }
                    VStack{
                        CustomerContact()
                    }
                    VStack(spacing:15){
                        VStack{
                            HStack{
                                InfoCard()
                            }
                        }
                        VStack{
                            HStack{
                                ScreenCard()
                            }
                        }
                        VStack{
                            HStack{
                                InfoCard2()
                            }
                        }
                    }
                }
            }
        }
                .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true)
        Spacer()
    }
}

}

这是我的主屏幕代码 HomeScreen Image

这就是问题所在,如果我在 HomeScreen 中使用导航,则会出现此默认后退箭头,当 NavigationView 不在 HomeScreen 中时,它在实时预览中看起来不错,但我需要在主屏幕中导航按钮,因此我需要使用 NavigationView在主屏幕中。我还能做什么来连接其他屏幕。

我是初学者,我需要帮助来完成这个项目

0 个答案:

没有答案