1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
   |  import SwiftUI
  struct NavigationStackView: View {     @State var presentSheetKey = false     @State var presentFullScreenCoverKey = false     var body: some View {         NavigationStack {             List {                 Section {                     NavigationLink(destination: PushView(),label: {Text("I am Root. Tap for Push View -1")})                                          NavigationLink{                         PushView()                     } label: {                         Text("I am Root. Tap for Push View -2")                     }                     NavigationLink("I am Root. Tap for Push View -3", destination: PushView())                                          NavigationLink("I am Root. Tap for Push View -4") {                         PushView()                     }                 } header: {                     Text("push")                 }                 Section {                     Button {                         self.presentSheetKey.toggle()                     } label: {                         Text("sheet").foregroundColor(.primary)                     }                                          Button {                         self.presentFullScreenCoverKey.toggle()                     } label: {                         Text("fullScreenCover").foregroundColor(.primary)                     }                 } header: {                     Text("present")                 }             }.navigationTitle("view跳转")         }         .sheet(isPresented: $presentSheetKey) {             //非全屏模式             PresentView()         }         .fullScreenCover(isPresented: $presentFullScreenCoverKey, content: {             //全屏模式             PresentView()         })     } }
  struct PushView: View {     @Environment(\.dismiss) var dismiss     var body: some View {         VStack {             Image(systemName: "phone")                 .resizable()                 .frame(width: 80, height: 80)             Text("hello")                 .font(.system(.title, design: .rounded))                 .fontWeight(.black)             Spacer()             Button("Here is Detail Push View. Tap to go back."){                 dismiss()             }         }     } }
  struct PresentView: View {     //用于退出该界面     //@Environment(\.presentationMode) var presentationMode     @Environment(\.dismiss) var dismiss     var body: some View {         VStack(alignment: .center, spacing: nil, content: {             Spacer()             HStack(content: {                 Spacer()             })             Button("Here is Detail Present View. Tap to go back.") {                 dismiss()                 // self.presentationMode.wrappedValue.dismiss()             }             .font(.system(size: 20))             .foregroundColor(.red)             .background(Color.white)             Spacer()         })         .background(Color.gray)         .navigationBarTitle("presentView", displayMode: .inline)     } }
  struct NavigationStackView_Previews: PreviewProvider {     static var previews: some View {         NavigationStackView()     } }
 
 
 
  |