SwiftUI confirationdialog在全屏视图?



我正在试验confirmationDialog修饰符(iOS 15中的新功能)。我想我可以像sheet一样使用它,但似乎你必须将它附加到屏幕上的某个小视图上(至少在我的iPad上)。有没有一种方法可以让一个人在屏幕中间显示为独立的?

例如,不能在iPad上使用。对话框是不可见的。
struct ContentView: View {
@State var showConf = false
var body: some View {
VStack(spacing: 0) {
Spacer(minLength: 20)
Button("Test Conf. Dialog") {
showConf = true
}
Spacer()
}
.frame(maxWidth: .infinity)
.background(Color.blue.opacity(0.3))
.confirmationDialog("Test", isPresented: $showConf) {
Button("Yes") {
print("Yes!")
}
}
}
}

试试这个,"confirmationDialogButton:

struct ContentView: View {
@State var showConf = false
var body: some View {
VStack(spacing: 0) {
Spacer(minLength: 20)
Button("Test Conf. Dialog") {
showConf = true
}
.confirmationDialog("Test", isPresented: $showConf) {
Button("Yes") {
print("Yes!")
}
}
Spacer()
}
.frame(maxWidth: .infinity)
.background(Color.blue.opacity(0.3))
}
}

最新更新