哪里学网站开发,邢台优化网站排名,网站建设和运行费用,关于推广网站的标题Swift UI 集成 IMKit 在 SwiftUI 中#xff0c;集成 IMKit 中 RCConversationListViewController 和 RCConversationViewController 两页面可能存在以下问题#xff1a; 1、直接在 View 中使用#xff0c;两个页面会错位#xff1b; 2、用 NavigationView 集成会话列表和会…Swift UI 集成 IMKit 在 SwiftUI 中集成 IMKit 中 RCConversationListViewController 和 RCConversationViewController 两页面可能存在以下问题 1、直接在 View 中使用两个页面会错位 2、用 NavigationView 集成会话列表和会话页面标题失效 分析 这两个页面强依赖导航 UINavigationController并且内部用的 frame 结算的布局。直接用放入 View 中会导致安全区域失效导致 frame 计算错误。 struct ContentView: View { var body: some View { ChatListView() } } 在 SwiftUI 中UIKit 的 UINavigationController 和 NavigationView 的标题兼容性不太好在二级页面设置 navigationBar 的 title 不生效。 解决方案 开发者需要用 UIViewControllerRepresentable 将 UIKit 的页面转换一下 struct ChatListView: UIViewControllerRepresentable { func makeUIViewController(context: Context) - UIViewController { let displayConversationTypeArray [ RCConversationType.ConversationType_PRIVATE.rawValue, RCConversationType.ConversationType_GROUP.rawValue, ] let collectionConversationType [ RCConversationType.ConversationType_SYSTEM.rawValue ] guard let conversationList RCDChatsViewController( displayConversationTypes: displayConversationTypeArray, collectionConversationType: collectionConversationType ) else { return UIViewController() } return UINavigationController(rootViewController: conversationList); } func updateUIViewController(_ uiViewController: UIViewController, context: Context) { } } 然后在合适的地方使用比如 ContentView 中注意需要使用 ignoresSafeArea 忽略安全区域。 struct ContentView: View { var body: some View { ChatListView() .ignoresSafeArea() } }