CNContactViewController navigationBar 不显示,或者alpha透明的解决方案

- (void)saveForNewContact {
    CNMutableContact *contact = [[CNMutableContact alloc] init];
    CNLabeledValue *labelValue =
    [CNLabeledValue labeledValueWithLabel:CNLabelPhoneNumberMobile
                                    value:[CNPhoneNumber phoneNumberWithStringValue:_phoneNum]];
    contact.phoneNumbers = @[labelValue];
    CNContactViewController *contactController = [CNContactViewController viewControllerForNewContact:contact];
    contactController.delegate = self;
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactController];
    [self settingNavBarForNavController:navController];
    [self  presentViewController:navController animated:YES completion:nil];
}

做一个延时,这是系统bug,会变透明,具体可以看 https://stackoverflow.com/questions/39793418/cncontactviewcontroller-navigation-bar-different-between-versions

- (void)settingNavBarForNavController:(UINavigationController *)navController {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        for (UIView *view in navController.navigationBar.subviews) {
            if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
                view.alpha = 1;
                return;
            }
        }
    });
}

你可能感兴趣的:(CNContactViewController navigationBar 不显示,或者alpha透明的解决方案)