SwiftUI 有这两个修饰符:
.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in
和
.sheet(isPresented: $showAlert,
一个提供操作表,另一个提供工作表(?)
为什么?如果有的话,这些元素之间有什么区别?
SwiftUI 有这两个修饰符:
.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in
和
.sheet(isPresented: $showAlert,
一个提供操作表,另一个提供工作表(?)
为什么?如果有的话,这些元素之间有什么区别?
用于显示某些视图模式的工作表,但 actionSheet 是一种警报视图!他们是非常不同的话题!
import SwiftUI
struct ContentView: View {
@State var showSheet = false
@State var showActionSheet = false
let appActionSheet = ActionSheet(title: Text("ActionSheet"), message: Text("I am an ActionSheet"), buttons: [
.default(Text("some text")),
.cancel()
])
var body: some View {
VStack
{
Button("show sheet") {showSheet.toggle()}.padding()
Button("show actionSheet") {showActionSheet.toggle()}.padding()
}.font(Font.title.bold())
.sheet(isPresented: $showSheet, content: {sheetView()})
.actionSheet(isPresented: $showActionSheet, content: {appActionSheet})
}
}
struct sheetView: View {
var body: some View {
ZStack
{
Color.red
Text("I am sheet view")
}.ignoresSafeArea()
}
}