SwiftUIの基本を身につけたい方はこちら

【SwiftUI】モーダル遷移の仕方

struct ContentView: View {
    @State var isPresentedSubView = false
    
    var body: some View {
        VStack {
            Button(action: {
                self.isPresentedSubView.toggle()
            }) {
                Text("モーダル画面を表示")
            }
            .sheet(isPresented: $isPresentedSubView) {
                SubView()
            }
        }
    }
}

struct SubView: View {
    var body: some View {
        VStack {
            Text("SubView")
        }
    }
}

評価