Created
August 13, 2020 01:44
-
-
Save yotubarail/aebc980c9a3104ace53be1d56158039e to your computer and use it in GitHub Desktop.
SwiftUIでのModalの扱い方
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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