[英]SwiftUI Preview Sheet w/o Running Live Preview?
Update from Apple Frameworks Engineer October 2020 : Apple 框架工程师2020 年 10 月更新:
Unfortunately there is no current workarounds to let you preview this outside of the live preview.
不幸的是,目前没有解决方法可以让您在实时预览之外进行预览。
Is it possible to create a SwiftUI preview of a presented sheet without running the Live Preview?是否可以在不运行实时预览的情况下为呈现的工作表创建 SwiftUI 预览? For example:
例如:
struct Sheet_Previews: PreviewProvider {
static var previews: some View {
Text("Background").sheet(isPresented: .constant(true)) {
Text("Sheet")
}
}
}
The above results in the following preview:以上结果产生以下预览:
In order for the sheet content to be presented in the preview, you must run the Live Preview:为了在预览中显示工作表内容,您必须运行实时预览:
Just let preview provide to show both views, for parent and sheet, like只需让预览提供显示父视图和工作表的两个视图,例如
struct Sheet_Previews: PreviewProvider {
static var previews: some View {
Group { // << will create two previews
Text("Background") // << parent view here
Text("Sheet") // << sheet view here
}
}
}
Xcode 13.0 seems to handle this correctly without starting a Live Preview. Xcode 13.0 似乎无需启动实时预览即可正确处理此问题。
So this is working now:所以这是现在工作:
struct Sheet_Previews: PreviewProvider {
static var previews: some View {
Text("Background").sheet(isPresented: .constant(true)) {
Text("Sheet")
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.