单击按钮后如何从 tabview 隐藏/删除视图

时间:2021-07-22 16:56:09

标签: ios swift xcode swiftui

我目前正在使用 tabview 来允许我的应用水平滚动。在 tabview 的末尾,用户会进入一个注册页面,在那里他们可以点击登录或注册。当他们单击其中一个时,我想将他们定向到一个新视图,在该视图中他们无法回滚到注册页面。目前,在他们单击登录或注册后会弹出一个新视图,但您仍然可以滚动回 tabview 中的前几页。任何帮助将不胜感激。

代码:

struct ContentView: View {

var body: some View {
    HStack {
        TabView {
            ForEach(0..<5) {i in
                if(i == 0) {
                    FirstPageView()
                } else if(i == 1) {
                    SecondPageView()
                } else if(i == 2) {
                    ThirdPageView()
                } else {
                    RegisterView()
                }
            }
        }.tabViewStyle(PageTabViewStyle())
        
    }
    
}

}

注册视图:

struct RegisterView: View {

var body: some View {
    let screen = UIScreen.main.bounds
    
    let screen_width = screen.size.width
    
    let screen_height = screen.size.height
    
    let theme_color =
        Color(hue: 0.636, saturation: 0.646, brightness: 0.994)
    
    NavigationView{
        VStack(alignment: .leading){
            
            Text("Investing App.")
                .foregroundColor(theme_color)
                .fontWeight(.bold)
                .font(.system(size:screen_width/8))
                .padding(.leading)
            
            
            Text("Start investing")
                .fontWeight(.bold)
                .font(.system(size:screen_width/8))
                .padding(.leading)
            
            
            Text("today.")
                .fontWeight(.bold)
                .font(.system(size:screen_width/8))
                .padding(.leading)
            
            NavigationLink(
                destination: SignUpView(),
                label: {
                    Text("Login")
                        .fontWeight(.bold)
                        .font(.system(size:screen_width/25))
                        .frame(width: screen_width/5, height: screen_width/9, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                        
                        .padding(.horizontal, screen_width/3)
                        .overlay(
                            RoundedRectangle(cornerRadius: 100)
                                .stroke(lineWidth: 1)
                        )
                })
            
            
            .frame(maxWidth: .infinity, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
            
            
            .offset(y:screen_height/2.5)
                NavigationLink(
                    destination: SignUpView(),
                    label: {
                        Text("Sign Up")
                            .fontWeight(.bold)
                            .font(.system(size:screen_width/25))
                            .frame(width: screen_width/5, height: screen_width/9, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                            
                            .padding(.horizontal, screen_width/3)
                            .overlay(
                                RoundedRectangle(cornerRadius: 100)
                                    .stroke(lineWidth: 1)
                            )
                    })
                    .frame(maxWidth: .infinity, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                    
                    
                    .offset(y:screen_height/5)
            
                
                
            
        }
        .padding()
        .offset(y: -screen_height/4+42.4)
        .frame(width: screen_width, height: screen_height/2, alignment: .leading)
        .navigationBarHidden(true)
    }
    .navigationViewStyle(StackNavigationViewStyle())
   
}

}

谢谢!

0 个答案:

没有答案