0

SwiftUI 有这两个修饰符:

.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in

.sheet(isPresented: $showAlert,

一个提供操作表,另一个提供工作表(?)

为什么?如果有的话,这些元素之间有什么区别?

4

1 回答 1

3

用于显示某些视图模式的工作表,但 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()
    }
}

在此处输入图像描述

在此处输入图像描述

于 2020-11-08T19:08:14.113 回答