A binding to a Boolean value that determines whether to present the action sheet that you create in the modifier’s content
closure. When the user presses or taps the sheet’s default action button the system sets this value to false
dismissing the sheet.
Instance Method
インスタンスメソッド
action
actionSheet(isPresented:content:)
Presents an action sheet when a given condition is true.
アクションシートを提示します、与えられた条件がrrueの場合に。
Availability 有効性
- iOS 13.0+
- iPadOS 13.0+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0–8.5 Deprecated
Technology
- Swift
UI
Declaration 宣言
func actionSheet(isPresented: Binding
<Bool
>, content: () -> ActionSheet
) -> some View
Parameters パラメータ
isPresented
content
A closure returning the
Action
to present. 提示するSheet Action
を返しているあるクロージャ。Sheet
Discussion 議論
In the example below, a button conditionally presents an action sheet depending upon the value of a bound Boolean variable. When the Boolean value is set to true
, the system displays an action sheet with both destructive and default actions:
struct ConfirmEraseItems: View {
private var isShowingSheet = false
var body: some View {
Button("Show Action Sheet", action: {
isShowingSheet = true
})
.actionSheet(isPresented: $isShowingSheet) {
ActionSheet(
title: Text("Permanently erase the items in the Trash?"),
message: Text("You can't undo this action."),
buttons:[
.destructive(Text("Empty Trash"),
action: emptyTrashAction),
.cancel()
]
)}
}
func emptyTrashAction() {
// Handle empty trash action.
}
}
Note 注意
In regular size classes in iOS, the system renders alert sheets as a popover that the user dismisses by tapping anywhere outside the popover, rather than displaying the default dismiss button.