swift - SwiftUI 中联系人应用程序的联系人列表

标签 swift uiviewcontroller swiftui cncontactpicker contactsui

您好,我正在尝试构建一个列出所有联系人的界面,就像具有相同UIContactsPhone 应用程序一样。到目前为止,我尝试过的内容如下。基本上,我尝试使用 UIViewControllerRepresentableContactsUI 实现 CNContactPickerViewController。但是我得到的是一个空白的白页。

struct ContactsViewController: UIViewControllerRepresentable {

    func makeUIViewController(context: UIViewControllerRepresentableContext<ContactsViewController>) -> CNContactPickerViewController {
        let controller = CNContactPickerViewController()
        controller.delegate = context.coordinator
        controller.displayedPropertyKeys = [CNContactGivenNameKey]
        return controller
    }

    func updateUIViewController(_ uiViewController: CNContactPickerViewController, context: UIViewControllerRepresentableContext<ContactsViewController>) {
        print("updating")
    }

    func makeCoordinator() -> Coordinator {
        return Coordinator(self)
    }

    class Coordinator: NSObject, CNContactPickerDelegate {
        var parent: ContactsViewController

        init(_ contactsViewController: ContactsViewController) {
            self.parent = contactsViewController
        }

    }
}

还有 SwiftUI 文件;

struct ContactsView: View {
    var body: some View {
        ContactsViewController()
    }
}

请注意,我在其他一些 SwiftUI 文件中调用 TabView 内部的 ContactsView。所以我想在 SwiftUI View 中显示联系人,它是 TabView 的一部分。任何帮助将非常感激。

最佳答案

这里有两种解决方案:https://stackoverflow.com/a/57621666/8818408

(1) 有效,但在显示联系人列表之前会闪烁一个 View 。对用户来说不是很好的体验。

(2) 类作品。它还会在显示联系人列表之前闪烁一个 View 。它沿前导、尾随和底部边缘显示出意想不到的透明度和意想不到的颜色。这些也许可以解决。

我刚刚开始尝试解决上面#2 的问题。如果有人能提供一个完全有效的解决方案,那就太好了。 Screen shot of #2

关于swift - SwiftUI 中联系人应用程序的联系人列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60116066/

相关文章:

ios - 在 loadView 中设置 UIView 的 backgroundColor 没有效果

swift - 如何从 SwiftUI 的列表中获取已删除行的索引?

SwiftUI:在编辑开始时清除 TextField

ios - SwiftUI - 在列表中的 View 内触发的动画也不会为列表设置动画

ios - Xcode "Use of undeclared type ' SomeClass'”错误但构建成功

ios - 将 Swift Delegate 设置为 "self"以外的 View Controller 的语法是什么?

ios - 如何强制 UIView 的 layoutSubviews?

macOS SwiftUI 按钮 "Active Area"父 View 的宽度

ios - Swift 如何使用自定义 UITableView 类将 UITableView 添加到 UIViewController

iOS, swift : Download multiple file serially and showing single progress bar for all file as a one progress