CNContactViewController导航栏版本之间有所不同

问题描述 投票:4回答:5

我们的色调是白色的。我们的应用程序使用CNContactViewController。在我们使用针对iOS 8和9的Xcode 7构建的商店中的应用程序版本中,如果您是iOS 9,我们调用了CNContactViewController。后退按钮为白色,但后面有一个灰色导航栏。在我们使用针对iOS 9和10的Xcode 8进行的开发构建中,没有灰色条,因此后退按钮在白色顶部是白色的,很难看到阴影。

有没有其他人在Xcode版本/ SDK版本之间经历过CNContactViewController的导航区域已经改变的变化?在我们的应用程序中可能会有一些其他更改会影响此栏吗?

编辑:这是我们最新版本中的图像。我确实删除了一些个人信息,所以这是中间的方框,但你可以在左上方看到很难看到后退按钮。

enter image description here

编辑:这是我们在整个应用程序中设置颜色的方式。如果白色后退按钮也使用红色的条形色调而不是任何东西,那么白色后退按钮就不会出现问题

    UINavigationBar.appearance().barTintColor = UIColor.red
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

我们使用的代码将其推送到具有红色条和白色按钮的现有导航控制器:

let ucvc = CNContactViewController(forUnknownContact: contact)
ucvc.delegate = self
ucvc.allowsEditing = true
ucvc.allowsActions = true
ucvc.alternateName = name()
ucvc.contactStore = CNContactStore()
self.navigationController?.pushViewController(ucvc, animated: true)
ios ios10 xcode8 uicolor cncontactviewcontroller
5个回答
6
投票

我遇到了完全相同的问题。它看起来像iOS 10的bug。无论如何,我通过将导航栏的半透明度设置为false来找到解决方法。然后将应用程序主窗口的背景颜色设置为您希望导航栏的颜色。

一些代码片段:

UINavigationBar.appearance().isTranslucent = false
UIApplication.shared.delegate?.window??.backgroundColor = UIColor.red

1
投票

我已经解决了这个问题:

CNContactViewController *vc = [CNContactViewController viewControllerForContact:contact];
vc.delegate = self;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    for (UIView *view in [vc.navigationController.navigationBar subviews]) {
        view.tintColor = [UIColor darkTextColor];

        view.backgroundColor = [UIColor redColor];
    }
});

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

1
投票

通过使用XCode的Debug View Hierarchy,我发现在推送CNContactViewController之后,UINavigationBar的名为“_UIBarBackground”的子视图的alpha变为0。

以下代码可以帮助我解决问题(在iOS 11中运行良好):

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        for (UIView *view in self.navigationController.navigationBar.subviews) {
            if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
                view.alpha = 1;
                break;
            }
        }
    });

0
投票

你的问题解决了我的问题:我现在知道为什么我有同样的问题。

我已经通过在推送CNContactViewController之前将navigationController.navigationBar.tintColor设置为蓝色阴影来解决它。退出时(在委托方法中)将其设置为白色。


0
投票

在Swift 5和Xcode 10.2中

在iOS 9.0 CNContactViewController导航栏中工作正常,但不是更高版本。

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(0.1 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {

   //Set status bar background colour
   let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
   statusBar?.backgroundColor = UIColor.red
   //Set navigation bar subView background colour
       for view in controller.navigationController?.navigationBar.subviews ?? [] {
          view.tintColor = UIColor.white
          view.backgroundColor = UIColor.red
       }
})

navigationController?.pushViewController(controller, animated: true)

这里我修复了状态栏背景颜色和导航栏背景颜色。如果你不想要状态栏颜色注释它。

完整的代码是

func addPhoneNumber(phNo:String) {
    if #available(iOS 9.0, *) {
        let store = CNContactStore()
        let contact = CNMutableContact()
        let homePhone = CNLabeledValue(label: CNLabelHome, value: CNPhoneNumber(stringValue : phNo))
        contact.phoneNumbers = [homePhone]
        let controller = CNContactViewController(forUnknownContact : contact)
        controller.contactStore = store
        controller.delegate = self

        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(0.1 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {

            //Set status bar background colour
            let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
            statusBar?.backgroundColor = UIColor.red
            //Set navigation bar subView background colour
            for view in controller.navigationController?.navigationBar.subviews ?? [] {
                view.tintColor = UIColor.white
                view.backgroundColor = UIColor.red
            }
        })

        navigationController?.pushViewController(controller, animated: true)
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.