Skip to content

Instantly share code, notes, and snippets.

@yotubarail
Created August 13, 2020 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yotubarail/aebc980c9a3104ace53be1d56158039e to your computer and use it in GitHub Desktop.
Save yotubarail/aebc980c9a3104ace53be1d56158039e to your computer and use it in GitHub Desktop.
SwiftUIでのModalの扱い方
import SwiftUI
struct ContentView: View {
@State var showModal = false
var body: some View {
Button(action: {
self.showModal.toggle()
}) {
Text("次のViewへ")
}
.sheet(isPresented: self.$showModal) {
NextView()
}
}
}
struct NextView: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
NavigationView {
Text("これはNextViewです")
.navigationBarTitle("NextView",displayMode: .inline)
.navigationBarItems(leading: Button("完了") {
self.presentationMode.wrappedValue.dismiss()
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment