SwiftUI - sheet 和 actionSheet 有什么区别?
SwiftUI - What is the difference between sheet and actionSheet?
SwiftUI 有这两个修饰符:
.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in
和
.sheet(isPresented: $showAlert,
一个呈现动作sheet,另一个呈现sheet (?)
为什么?如果有的话,这些元素之间有什么区别?
sheet 用于显示一些视图 modal-way,但 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()
}
}
SwiftUI 有这两个修饰符:
.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in
和
.sheet(isPresented: $showAlert,
一个呈现动作sheet,另一个呈现sheet (?)
为什么?如果有的话,这些元素之间有什么区别?
sheet 用于显示一些视图 modal-way,但 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()
}
}