A binding to a Boolean value that determines whether to present the sheet that you create in the modifier’s content
closure.
Instance Method
インスタンスメソッド
sheet(is
sheet(isPresented:onDismiss:content:)
Presents a sheet when a binding to a Boolean value that you provide is true.
Availability 有効性
- iOS 13.0+
- iPadOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
Technology
- Swift
UI
Declaration 宣言
Parameters パラメータ
isPresented
onDismiss
The closure to execute when dismissing the sheet.
content
A closure that returns the content of the sheet.
Discussion 議論
Use this method when you want to present a modal view to the user when a Boolean value you provide is true. The example below displays a modal view of the mockup for a software license agreement when the user toggles the is
variable by clicking or tapping on the “Show License Agreement” button:
struct ShowLicenseAgreement: View {
private var isShowingSheet = false
var body: some View {
Button(action: {
isShowingSheet.toggle()
}) {
Text("Show License Agreement")
}
.sheet(isPresented: $isShowingSheet,
onDismiss: didDismiss) {
VStack {
Text("License Agreement")
.font(.title)
.padding(50)
Text("""
Terms and conditions go here.
""")
.padding(50)
Button("Dismiss",
action: { isShowingSheet.toggle() })
}
}
}
func didDismiss() {
// Handle the dismissing action.
}
}