Present ActionSheet in SwiftUI on iPad

前端 未结 5 1692
梦谈多话
梦谈多话 2021-02-02 09:45

I\'ve gotten an ActionSheet to present just fine on an iPhone device. But it crashes for iPad. Says it needs the location for the popover. Has anyone had luck with this code? I\

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 10:19

    Finally, as tested in iOS 13.4 this has been resolved, at least in the beta. The conflicting constraints warning persists, but the crash is gone. This is now the appropriate way to present an action sheet.

    import SwiftUI
    
    struct ContentView : View {
        @State var showSheet = false
    
        var body: some View {
            VStack {
                Button(action: {
                    self.showSheet.toggle()
                }) {
                    Text("Show")
                }
                .actionSheet(isPresented: $showSheet, content: { ActionSheet(title: Text("Hello"))
                })
            }
        }
    }
    
    struct ContentView_Previews : PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }
    

提交回复
热议问题