在许多项目中,我使用SnapKit。还有新的项目。在项目中,我有ViewController,它与SwiftUI视图连接:
class OfficeListViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let vc = UIHostingController(rootView: OfficeListView())
addChild(vc)
view.addSubview(vc.view)
vc.didMove(toParent: self)
vc.view.translatesAutoresizingMaskIntoConstraints = false
// Here I want to set constraints to vc
vc.snp // throws error: Value of type 'UIHostingController<OfficeView>' has no member 'snp'
}
}
struct OfficeListView: View {
var body: some View {
Text("View")
}
}但它会抛出错误:
'UIHostingController‘类型的UIHostingController值没有成员'snp’
如何正确使用SnapKit与其结合使用?
发布于 2020-07-18 12:46:08
UIHostingController只是UIViewController的子类,它在常规UIView中呈现SwiftUI视图。如果您想设置约束,那么您应该像我们通常使用视图那样使用vc.view。
https://stackoverflow.com/questions/62968408
复制相似问题