4

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

有没有其他人经历过 CNContactViewController 的导航区域发生变化的 Xcode 版本/SDK 版本之间的变化?我们的应用程序中是否有其他一些变化会影响这个栏?

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

在此处输入图像描述

编辑:这就是我们在整个应用程序中设置颜色的方式。如果白色的后退按钮也使用红色的条形颜色而不是什么都没有,则它不会成为问题

    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)
4

6 回答 6

6

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

一些代码片段:

UINavigationBar.appearance().isTranslucent = false
UIApplication.shared.delegate?.window??.backgroundColor = UIColor.red
于 2017-02-16T17:33:00.207 回答
2

我已经这样解决了:

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];
于 2017-10-20T16:14:09.247 回答
1

在 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)
    }
}
于 2019-04-24T05:43:19.897 回答
1

通过使用XCode的Debug View Hierarchy,我发现UINavigationBar的名为“_UIBarBackground”的子视图的alpha在CNContactViewController被推送后变为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;
            }
        }
    });
于 2018-05-20T12:20:30.057 回答
0

只需子类化 CNContactViewController

    class MyAwesomeViewController: CNContactViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.navigationController?.navigationBar.subviews.forEach({ (aView) in
            aView.backgroundColor = UIColor.red
        })
    }
    
}
于 2021-03-09T09:16:56.490 回答
0

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

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

于 2017-01-30T11:35:23.700 回答