考察点:UIViewRepresentable / UIHostingController 互操作桥接。
要点:
UIViewRepresentable 协议,实现 makeUIView(context:) 创建 UIKit 视图、updateUIView(_:context:) 同步状态、dismantleUIView 清理;常用场景是封装 WKWebView、地图 MKMapView 等 SwiftUI 暂无的组件。UIHostingController(rootView:) 把 SwiftUI 视图包装成 UIViewController,可 push/present 进现有 UIKit 页面栈;也可通过 UIHostingConfiguration 在 UITableViewCell/UICollectionViewCell 里直接放 SwiftUI 内容。UIViewControllerRepresentable 包装 UIViewController(如系统图片选择器、相机)。@EnvironmentObject / Binding 与 SwiftUI 状态联动,保持单一数据源。题目与答案就在本页;收藏、批注和错题重练在应用内