首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SnapKit snp不能分配给UIHostingController

SnapKit snp不能分配给UIHostingController
EN

Stack Overflow用户
提问于 2020-07-18 12:10:14
回答 1查看 383关注 0票数 0

在许多项目中,我使用SnapKit。还有新的项目。在项目中,我有ViewController,它与SwiftUI视图连接:

代码语言:javascript
复制
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与其结合使用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-18 12:46:08

UIHostingController只是UIViewController的子类,它在常规UIView中呈现SwiftUI视图。如果您想设置约束,那么您应该像我们通常使用视图那样使用vc.view

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62968408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档