在iPad上的SwiftUI中呈现ActionSheet [英] Present ActionSheet in SwiftUI on iPad
问题描述
我已经收到一个ActionSheet,可以在iPhone设备上正常显示.但是它在iPad上崩溃了.说它需要弹出窗口的位置.有人用过此代码吗?我正在使用iOS 13 beta 3和Xcode 11 beta3.(此版本使用的是无法显示Beta 2中提供的ActionSheet的版本)
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'm using iOS 13 beta 3 and Xcode 11 beta 3. (This uses a version of presenting the ActionSheet not available in beta 2)
import SwiftUI
struct ContentView : View {
@State var showSheet = false
var body: some View {
VStack {
Button(action: {
self.showSheet.toggle()
}) {
Text("Show")
}
.presentation($showSheet) { () -> ActionSheet in
ActionSheet(title: Text("Hello"))
}
}
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
推荐答案
最后,如在iOS 13.4中测试的那样,至少在beta中,此问题已得到解决.冲突的约束警告仍然存在,但是崩溃不见了.现在,这是呈现操作表的适当方法.
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()
}
}
这篇关于在iPad上的SwiftUI中呈现ActionSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!