简体   繁体   中英

How to make the screen change when clicking on the button in SwiftUI

I want to make it so that when the button is pressed, the screen (NavigationView) changes from the current one to another.And at the same time, so that it was impossible to return to the previous screen after pressing the button (no menu in the upper left corner). Many thanks in advance for your help! My code (ContentView):



import SwiftUI



struct acquaintance1: View {
    // Первый экран знакомства
    var body: some View {
        ZStack{
                Button (action: {})
                {
                    VStack{
                        ZStack{
                            VStack{
                                Image("scren1")
                                    .resizable()
                                    .overlay {
                                        Button {
                                           // any action
                                            
                                            let impactMed = UIImpactFeedbackGenerator(style: .heavy)
                                            impactMed.impactOccurred()
                                        } label: {
                                            Image(systemName: "arrow.right.square.fill")
                                                    .font(.system(size: 50))
                                                    .foregroundColor(Color(.systemOrange))
                                                    .position(x: 349, y: 621)
                                                    
                                        }
                                    }
                            }
                            
                        }
                    }
                }
        }
    }
}



// Второй экран знакомства
struct View1_1: View {
    var body: some View {
        NavigationLink {
            View1_2()
        } label: {
            Text("Переход на View1_2")
        }
        .navigationTitle("View1_1")
    }
}
// Третий экран знакомства
struct View1_2: View {
    var body: some View {
        Text("Последний экран")
    }
}



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        acquaintance1()
    }
}


Add the following on the next view after the button is clicked;

  struct View1_2: View {
   var body: some View {
    Text("Последний экран")
    .navigationBarBackButtonHidden(true) // Add this
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM