更新 Xcode 13
下面的代码示例在 Xcode 13 中按预期工作。
来自 Apple 框架工程师的更新 October 2020 :
Unfortunately there is no current workarounds to let you preview this outside of the live preview.
是否可以在不运行实时预览的情况下为呈现的工作表创建 SwiftUI 预览?例如:
struct Sheet_Previews: PreviewProvider {
static var previews: some View {
Text("Background").sheet(isPresented: .constant(true)) {
Text("Sheet")
}
}
}
以上结果产生以下预览:为了在预览中显示工作表内容,您必须运行实时预览:
最佳答案
Xcode 13.0 似乎无需启动实时预览即可正确处理此问题。
所以这是现在工作:
struct Sheet_Previews: PreviewProvider {
static var previews: some View {
Text("Background").sheet(isPresented: .constant(true)) {
Text("Sheet")
}
}
}
关于没有运行实时预览的 SwiftUI 预览表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64096402/