我需要在visionOS应用程序中使用呈现的工作表(不是Popover)。让工作表正确显示很简单,但我无法在模拟器中通过手势(即向下滑动)让它消失。程序化的解雇是有效的,但从 UI 的角度来看很笨拙。
这是代码:
struct ContentView: View {
@State var displaySheet : Bool = false
var body: some View {
VStack {
Toggle("Display Sheet", isOn: $displaySheet)
.toggleStyle(.switch)
.padding(.horizontal,100)
}
.padding()
.sheet(isPresented: $displaySheet, content: {
PresentedSheetView()
})
}
}
struct PresentedSheetView: View {
var body: some View {
VStack {
Text("This is the presented sheet!")
}
.padding()
.frame(width: 400, height: 400)
}
}
向下滑动不起作用。
.onTapGesture
关闭也不起作用,因为在真实的应用程序中还有其他通过点击激活的控件。
我可以重现这个问题。您应该使用反馈助手提交错误报告。
目前,您可以将
Button
添加到 toolbar
或 onTapGesture
,但这些解决方案都不是理想的。
.sheet(isPresented: $displaySheet, content: {
PresentedSheetView()
.onTapGesture {
displaySheet.toggle()
}
})