Ron*_*nie 1 swift swiftui actionsheet
SwiftUI 有以下两个修饰符:
.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in
Run Code Online (Sandbox Code Playgroud)
和
.sheet(isPresented: $showAlert,
Run Code Online (Sandbox Code Playgroud)
一个提出了一个行动表,另一个提出了一个表(?)
为什么?这些元素之间有什么区别(如果有的话)?
用于显示某些视图模式的工作表,但 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()
}
}
Run Code Online (Sandbox Code Playgroud)