dtorreci4ejg dtorreci4ejg - 21 days ago 16
iOS Question

CNContactViewController hiding navigation bar

When I push a

CNContactViewController
on to the stack of
UITableViewController
subclass which is within a
UINavigationController
, the top navigation bar is almost entirely hidden. But with the brightness all the way up, you make out the back arrow followed by the word "Detail", and the system status bar. When I tap that corner of the screen, the CNContactViewController is indeed dismissed.

enter image description here

Of course this is not good, since a user would probably not even see the text of the navigation bar and now to press any buttons to dismiss.

Is there any way to make the navigation bar tint of the CNContactViewController be the same as the view controller that showed it (the rest of my app)?

CNContactViewController *controller = [CNContactViewController viewControllerForUnknownContact:person];

controller.contactStore = [[CNContactStore alloc] init];
controller.delegate = self;
controller.allowsActions = NO;

[self.navigationController pushViewController:controller animated:YES];


I should note that I'm only experiencing this problem on iOS 10, and not versions below 10. I also do get the properly tinted navigation bar when I tap "Add to Existing Contact", but it breaks again when that view controller is dismissed.

enter image description here

So again, my question is: Is there any way to make the navigation bar tint of the CNContactViewController be the same as the view controller that showed it (the rest of my app)?

Answer

Your second screen shot shows the reason for this problem: you have set the tint color for your bar (or bar button items in general) to be white. Hence, they are white in front of the transparent navigation bar and white background in the contact view controller.

You can't do anything directly about the bar tint color, but you can solve this in either of two ways:

  • One is to make your navigation bar nontranslucent. In that case, the contact view controller's navigation bar will be black, and your white bar button items will be visible.

  • Another approach is to change your navigation bar's tint color (not the bar tint color, but the tint color that it communicates down to its bar button items) as the contact view controller pushes, and change it back when it pops.

EDIT Okay, I see that there's a further problem because the New Contact view controller is a further view controller presented in front of yours. If you refuse to give up your white bar button item setting, you will have to use the appearance proxy to set the UIBarButtonItem tint color to something else when your push the contact view controller, and then reset it back to your white when your navigation controller delegate tells you that the user is popping back to your view controller.