CNContactViewController隐藏导航栏

当我将一个CNContactViewController放到UINavigationControllerUITableViewController子类的堆栈上时,顶部导航栏几乎完全隐藏。 但是,随着亮度的提高,您可以确定后退箭头,然后是“Detail”(细节)和系统状态栏。 当我点击屏幕的那个angular落时,CNContactViewController确实被解散了。

在这里输入图像说明

当然这不好,因为用户可能甚至不会看到导航栏的文本,现在按任何button来解散。

有什么办法使CNContactViewController的导航栏的色调与显示它的视图控制器(我的应用程序的其余部分)相同?

 CNContactViewController *controller = [CNContactViewController viewControllerForUnknownContact:person]; controller.contactStore = [[CNContactStore alloc] init]; controller.delegate = self; controller.allowsActions = NO; [self.navigationController pushViewController:controller animated:YES]; 

我应该注意到,我只在iOS 10遇到这个问题,而不是在10以下的版本。我点击“添加到现有的联系人”,但我也得到正确的染色的导航栏,但当视图控制器被解散时,它再次打破。

在这里输入图像说明

所以再次,我的问题是: 有没有办法使CNContactViewController的导航栏色调是相同的视图控制器显示它(我的应用程序的其余部分)?

您的第二个屏幕快照显示出现此问题的原因:已将条形(或一般条形button项目)的色调设置为白色。 因此,它们在透明导航栏前为白色,在联系人视图控制器中为白色背景。

你不能直接对酒吧的色调做任何事情,但你可以用两种方法解决这个问题:

  • 一个是让你的导航栏不透明。 在这种情况下,联系人视图控制器的导航栏将变为黑色,并且您的白色栏button项目将可见。

  • 另一种方法是在联系人视图控制器按下时更改导航栏的色调颜色(不是色条的颜色,但是与其通信的色调颜色),并在popup时将其更改回来。

编辑好吧,我看到还有一个问题,因为新的联系人视图控制器是一个进一步的视图控制器呈现在你的面前。 如果您拒绝放弃您的白色栏button项目设置,则当您按下联系人视图控制器时,必须使用外观代理来将UIBarButtonItem色调设置为其他颜色,然后当您的导航控制器重置为白色时代表告诉你用户正在弹回到你的视图控制器。

我花了几个小时与CNContactViewController摔跤试图强迫它适应我的UINavigation外观设置,但它不会。 它有它自己的外观和感觉。 我查看了诸如Mail和Notes之类的iOS应用程序,看看它们是如何显示CNContactViewController的,它看起来像是一个popup窗口,所以我也这么做了。

即使这不是微不足道的。 CNContactViewController必须包装在一个UINavigationView中,这样Create New Contact和其他视图才能被推送。 如果你已经重写了UINavigationBar的外观默认值,你需要在之前和之后设置它们回到标准。 以下是最后的样子:

 @property (strong, nonatomic) CNContactViewController *contactViewController; @property (assign, nonatomic) UIBarStyle saveAppearanceBarStyle; @property (strong, nonatomic) UIColor *saveAppearanceBarTintColor; @property (strong, nonatomic) UIColor *saveAppearanceTintColor; @property (strong, nonatomic) UIColor *saveAppearanceBackgroundColor; @property (strong, nonatomic) NSDictionary<NSAttributedStringKey, id> * saveAppearanceTitleTextAttributes; @property (assign, nonatomic) BOOL saveAppearanceTranslucent; - (IBAction)onAddToContactsButtonTapped:(id)sender self.contactViewController = [CNContactViewController viewControllerForUnknownContact: ... ]; // as before [self suspendNavBarAppearanceSettings]; UINavigationController *popNav = [[UINavigationController alloc] initWithRootViewController:self.contactViewController]; popNav.modalPresentationStyle = UIModalPresentationPopover; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(onAddToContactsDoneTapped:)]; self.contactViewController.navigationItem.leftBarButtonItem = doneButton; [self presentViewController:popNav animated:YES completion:nil]; UIPopoverPresentationController *popoverController = newNav.popoverPresentationController; popoverController.permittedArrowDirections = UIPopoverArrowDirectionAny; popoverController.sourceRect = ...; // where you want it to point popoverController.sourceView = ...; // where you want it to point popoverController.delegate = self; } - (void) suspendNavBarAppearanceSettings { self.saveAppearanceBarStyle = [UINavigationBar appearance].barStyle; self.saveAppearanceBarTintColor = [UINavigationBar appearance].barTintColor; self.saveAppearanceTintColor = [UINavigationBar appearance].tintColor; self.saveAppearanceBackgroundColor = [UINavigationBar appearance].backgroundColor; self.saveAppearanceTitleTextAttributes = [UINavigationBar appearance].titleTextAttributes; self.saveAppearanceTranslucent = [UINavigationBar appearance].translucent; [UINavigationBar appearance].barStyle = UIBarStyleDefault; [UINavigationBar appearance].barTintColor = nil; [UINavigationBar appearance].tintColor = nil; [UINavigationBar appearance].backgroundColor = nil; [UINavigationBar appearance].titleTextAttributes = nil; [UINavigationBar appearance].translucent = YES; } - (void) restoreNavBarAppearanceSettings { [UINavigationBar appearance].barStyle = self.saveAppearanceBarStyle; [UINavigationBar appearance].barTintColor = self.saveAppearanceBarTintColor; [UINavigationBar appearance].tintColor = self.saveAppearanceTintColor; [UINavigationBar appearance].backgroundColor = self.saveAppearanceBackgroundColor; [UINavigationBar appearance].titleTextAttributes = self.saveAppearanceTitleTextAttributes; [UINavigationBar appearance].translucent = self.saveAppearanceTranslucent; } - (void)onAddToContactsDoneTapped:(id)sender { [self restoreNavBarAppearanceSettings]; [[self presentedViewController] dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - CNContactViewControllerDelegate - (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact { [self restoreNavBarAppearanceSettings]; [[self presentedViewController] dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - UIPopoverPresentationControllerDelegate - (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController { // This method is only called if we are presented in a popover, ie on iPad // as opposed to full screen like on a phone. // on iPad you just tap outside to finish, so remove the Done button self.contactViewController.navigationItem.leftBarButtonItem = nil; } - (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { [self restoreNavBarAppearanceSettings]; } 
Interesting Posts