swift - 视图内容没有出现在 UIScrollView 中
问题描述
我有这个...
func makeUIView(context: Context) -> UIScrollView {
let control = UIScrollView()
control.addSubview(UIHostingController(rootView: preview).view)
return control
}
如果我将preview
视图放在自定义滚动视图之外,那么我可以看到它。但是当我将它添加为 a 的子视图时,UIScrollView
我什么也看不到。
我是否正确添加了它?
这是我从这里获得的滚动视图的完整代码。
import SwiftUI
import Foundation
struct LegacyScrollView : UIViewRepresentable {
var preview: AnyView
init(preview: AnyView) {
self.preview = preview
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
func makeUIView(context: Context) -> UIScrollView {
let control = UIScrollView()
control.addSubview(UIHostingController(rootView: preview).view)
return control
}
func updateUIView(_ uiView: UIScrollView, context: Context) {
}
class Coordinator: NSObject {
var control: LegacyScrollView
init(_ control: LegacyScrollView) {
self.control = control
}
@objc func handleRefreshControl(sender: UIRefreshControl) {
sender.endRefreshing()
}
}
}
解决方案
推荐阅读
- swiftui - 带有数值的格式化程序错误的Swiftui TextField
- excel - 根据excel中的其他列值为列分配值
- javascript - ramda 阵列清理数据以产生唯一的阵列
- magento2 - Magento 2.3.3 问题:在产品页面上传图片时出错
- windows - 从命令行构建 docker 容器(Windows)
- reactjs - 如何更改 ionic v4 React 上的 onClick 元素?
- php - Laravel 不显示来自 url 的图像
- sql - 如何在id上合并两个表sql?
- c# - Gridview 列未设置为我输入的宽度
- r - 在带有管道函数的向量中应用 is.na() 函数