ios - SwiftUI:UIViewRepresentable 小部件预览
问题描述
要预览UIViewRepresentable
结构,我有以下代码:
import SwiftUI
import WidgetKit
struct ViewRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
return UIView()
}
func updateUIView(_ uiView: UIView, context: Context) {
}
typealias UIViewType = UIView
}
struct ViewRepresentable_Previews: PreviewProvider {
static var previews: some View {
ViewRepresentable().previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
它输出以下诊断信息。
RemoteHumanReadableError: Failed to update preview
invalid TimelineEntries
错误是“无法在此文件中预览 - 无法更新预览”
你如何解决这个错误?
解决方案
包裹在 UIViewRepresentable 中的 UIKit 视图在 WidgetKit 中不起作用。
来源:https ://developer.apple.com/forums/thread/653471?answerId=619627022#619627022
推荐阅读
- ios - 使用 UIImagePickerController() 选择图像会自动旋转它们
- python - 分配唯一年月组合的计数
- bayesian - PyMC3 在 Metropolis 采样中比 PyMC 慢得多
- javascript - 生成翻译 CSV 文件
- python - collectstatic 指的是错误的目录
- animation - CurvedAnimation 不尊重 Curve 类型
- django - get_or_create 创建或找到对象?
- extjs - 选择父标题时如何确保选择嵌套标题-Extjs
- python - Python:动态访问属性的类型注释
- django - Django MPTT:在迁移文件中重建树