Home > AI > IOS > SwiftUI >

.sheet

Example 1:

ParentView.swift

struct ParentView: View {
    @State var isPresented = false
    
    var body: some View {
        Button(action: {
            self.isPresented = true
        }, label: {
            Text("Show Child View")
        }).sheet(isPresented: $isPresented, content: {
            ChildView()
        })
    }
}

ChildView.swift

struct ChildView: View {
    @Environment(\.presentationMode) var mode
    
    var body: some View {
        Button(action: {
            print(self.mode.wrappedValue.isPresented)
            self.mode.wrappedValue.dismiss()
        }, label: {
            Text("Dismiss")
        })
    }
}

 

Leave a Reply