iPad 上的 ActionSheet 未正确显示 SwiftUI

ActionSheet on iPad not showing properly SwiftUI

我试图让我的用户在 ActionSheet 中选择拍照或从图库中选择

它在 Iphone 上运行良好,但在 Ipad

上运行不佳

在 Ipad 上:ActionSheet 位于屏幕顶部,不可读...

我在 Whosebug 上读到的关于这个问题的所有问题都是关于崩溃的(这不是我的情况)或者比 SwiftUI 更早

我的代码:

     struct AjoutView: View {
    @State private var image : Image?
    @State private var shouldPresentImagePicker = false
    @State private var shouldPresentActionScheet = false
    @State private var shouldPresentCamera = false
    
    var body: some View {
     VStack{
      ...
     }
        .sheet(isPresented: $shouldPresentImagePicker, onDismiss: loadImage) {
            SUImagePickerView(sourceType: self.shouldPresentCamera ? .camera : .photoLibrary, image: self.$image, isPresented: self.$shouldPresentImagePicker, dispId: disp.id)
                }
        .actionSheet(isPresented: $shouldPresentActionScheet) { () -> ActionSheet in
                    ActionSheet(title: Text("Ajouter une photo"), buttons: [ActionSheet.Button.default(Text("Prendre une photo"), action: {
                        self.shouldPresentImagePicker = true
                        self.shouldPresentCamera = true
                    }), ActionSheet.Button.default(Text("Importer depuis mes photos"), action: {
                        self.shouldPresentImagePicker = true
                        self.shouldPresentCamera = false
                    }), ActionSheet.Button.cancel()])
    
            }
    }
}

我的代码中缺少什么?

将它附加到您的 View 中的某个东西上,例如使它显示的 Button

struct ASSample: View {
    @State var shouldPresentActionScheet1: Bool = false
    @State var shouldPresentActionScheet2: Bool = false

    var body: some View {
        VStack{
            Button("show-sheet1", action: {
                self.shouldPresentActionScheet1.toggle()
            })
            .actionSheet(isPresented: $shouldPresentActionScheet1) { () -> ActionSheet in
                ActionSheet(title: Text("Ajouter une photo"), buttons: [ActionSheet.Button.default(Text("Prendre une photo"), action: {
                    //self.shouldPresentImagePicker = true
                    //self.shouldPresentCamera = true
                }), ActionSheet.Button.default(Text("Importer depuis mes photos"), action: {
                    //self.shouldPresentImagePicker = true
                    //self.shouldPresentCamera = false
                }), ActionSheet.Button.cancel()])
                
            }

            Spacer()
            Button("show-sheet2", action: {
                self.shouldPresentActionScheet2.toggle()
            })
            .actionSheet(isPresented: $shouldPresentActionScheet2) { () -> ActionSheet in
                ActionSheet(title: Text("Ajouter une photo"), buttons: [ActionSheet.Button.default(Text("Prendre une photo"), action: {
                    //self.shouldPresentImagePicker = true
                    //self.shouldPresentCamera = true
                }), ActionSheet.Button.default(Text("Importer depuis mes photos"), action: {
                    //self.shouldPresentImagePicker = true
                    //self.shouldPresentCamera = false
                }), ActionSheet.Button.cancel()])
                
            }
        }
        
    }
    
}

struct ASSample_Previews: PreviewProvider {
    static var previews: some View {
        ASSample()
    }
}