實例方法
sheet(is
sheet(isPresented:onDismiss:content:)
當與您提供的布爾值的綁定為真時顯示工作表。
聲明
func sheet<Content>(
isPresented: Binding<Bool>,
onDismiss: (() -> Void)? = nil,
content: @escaping () -> Content
) -> some View where Content : View
參數
isPresented
與布爾值的綁定,該值確定是否顯示您在修改器的
content
閉包中創建的工作表。onDismiss
關閉工作表時要執行的關閉。
content
返回工作表內容的閉包。
詳述
當您提供的布爾值為真時,如果您想向用戶呈現模式視圖,請使用此方法。當用戶通過單擊或點擊 “Show License Agreement” 按鈕來切換 isShowingSheet
變量時,以下示例顯示了軟件許可協議模型的模式視圖:
struct ShowLicenseAgreement: View {
@State 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.
}
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Optional sheet(item:onDismiss:content:)用法及代碼示例
- Swift Optional shadow(color:radius:x:y:)用法及代碼示例
- Swift Optional symbolVariant(_:)用法及代碼示例
- Swift Optional saturation(_:)用法及代碼示例
- Swift Optional submitLabel(_:)用法及代碼示例
- Swift Optional speechAlwaysIncludesPunctuation(_:)用法及代碼示例
- Swift Optional submitScope(_:)用法及代碼示例
- Swift Optional scaledToFill()用法及代碼示例
- Swift Optional searchCompletion(_:)用法及代碼示例
- Swift Optional safeAreaInset(edge:alignment:spacing:content:)用法及代碼示例
- Swift Optional simultaneousGesture(_:including:)用法及代碼示例
- Swift Optional scaledToFit()用法及代碼示例
- Swift Optional scenePadding(_:)用法及代碼示例
- Swift Optional scaleEffect(_:anchor:)用法及代碼示例
- Swift Optional scaleEffect(x:y:anchor:)用法及代碼示例
- Swift Optional swipeActions(edge:allowsFullSwipe:content:)用法及代碼示例
- Swift Optional popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代碼示例
- Swift Optional mask(alignment:_:)用法及代碼示例
- Swift Optional listSectionSeparatorTint(_:edges:)用法及代碼示例
- Swift Optional badge(_:)用法及代碼示例
- Swift Optional fullScreenCover(isPresented:onDismiss:content:)用法及代碼示例
- Swift Optional keyboardType(_:)用法及代碼示例
- Swift Optional clipShape(_:style:)用法及代碼示例
- Swift Optional preferredColorScheme(_:)用法及代碼示例
- Swift Optional background(_:ignoresSafeAreaEdges:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional sheet(isPresented:onDismiss:content:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。