我正在尝试实现CNContactViewDelegate
以显示CNContact
的详细信息。显然,我是第一个使用SwiftUI
实现它并且遇到了问题。无论如何,我可以使用UIViewControllerRepresentable
查看CNContact
的详细信息,但是我在NavigationBar
上遇到了问题,因为NavigationBar
和NavigationLink
之间存在间隙,这会导致Contact
的图像和StatusBar
之间存在间隙-我认为是这个原因-而且原生的Contacts
应用程序中没有这种间隙,这也存在于此链接所实现的UIKit
框架中。
以下是代码;
struct ContactsListView: View {
@ObservedObject var contactsModel: ContactsViewModel
var body: some View {
NavigationView{
List {
//After some ForEach's and Section's
//This view is working.
NavigationLink(destination: ContactDetailView(contact: self.$contactsModel.contacts[sectionIdx].contacts[contactIdx])) {
Text(self.contactsModel.contacts[sectionIdx].contacts[contactIdx].givenName)
}
}
.navigationBarTitle("Contacts")
}
}
}
struct ContactView: UIViewControllerRepresentable {
@Binding var contact: CNContact
func makeCoordinator() -> ContactView.Coordinator {
Coordinator(self)
}
func makeUIViewController(context: UIViewControllerRepresentableContext<ContactView>) -> CNContactViewController {
let controller = CNContactViewController(for: contact)
self.navigationBarHidden(true)
return controller
}
func updateUIViewController(_ uiViewController: CNContactViewController, context: UIViewControllerRepresentableContext<ContactView>) {
print(context)
}
class Coordinator: NSObject, CNContactViewControllerDelegate {
var parent: ContactView
init(_ contactDetail: ContactView) {
self.parent = contactDetail
self.parent.navigationBarHidden(true)
}
}
}
在
ContactView
中,这两个self.navigationBarHidden(true)
都没有起作用。以下是问题的示例,原生应用程序的截图;
这是我的代码的结果;