我正在试验confirmationDialog
修饰符(iOS 15中的新功能)。我想我可以像sheet
一样使用它,但似乎你必须将它附加到屏幕上的某个小视图上(至少在我的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!")
}
}
}
}
试试这个,"confirmationDialog
到Button
:
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))
}
}