【问题标题】:iOS13 UIDocumentPickerViewController - open directory does not display select/open/cancel buttonsiOS13 UIDocumentPickerViewController - 打开目录不显示选择/打开/取消按钮
【发布时间】:2019-10-04 18:12:14
【问题描述】:

我正在使用 UIDocumentPickerViewController 浏览并让用户选择一个目录,但在 iOS 13 上,当显示此 UIDocumentPickerViewController 时,不显示应该显示的按钮,如选择/取消和打开/完成,但是当你点击它时location 它的行为就像按钮可见时的行为一样。此外,此问题仅在 iOS 13 上出现。使用相同的代码,按钮显示在 iOS 12 上。感谢任何帮助

对于 AppDelegate didFinishLaunchingWithOptions 中的 UIDocumentBrowserViewController 实例,我确实将导航栏的色调颜色设置为 nil。

if #available(iOS 11.0, *) {
    UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = nil
} 


//Here is how UIDocumentPickerViewController is created and presented
let documentPickerViewController = UIDocumentPickerViewController(documentTypes:["public.folder"], in: .open)
...
...
...

self!.documentPickerViewController.delegate = self!
self!.documentPickerViewController.allowsMultipleSelection = true
self!.documentPickerViewController.modalPresentationStyle = .fullScreen     

self!.navigationController?.present(self!.documentPickerViewController, animated: true, completion:nil)

这是截图

编辑: 这是视图层次结构-不知道为什么在 iOS 13 上使用 DOCExportModeViewController。在 iOS 12 上,它是相同代码的 UIDocumentBrowserViewController。有什么想法可以解决这个问题吗?

【问题讨论】:

  • 我在浅色模式下观察到这种行为,按钮似乎在那里,但白底白字,因此不可见。这就是为什么他们仍然通过了解自己的位置来工作。

标签: ios swift xcode ios13 uidocumentpickerviewcontroller


【解决方案1】:

如果在多个地方使用文档 ViewController 或任何其他选择器,我发现了这个快速修复:

if #available(iOS 11.0, *) {
    UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = nil
}

如果您担心一个地方或在不同地方有不同的颜色,您可以在ViewWillAppear 中设置色调颜色并在ViewWillDisappear 方法中重置它。

【讨论】:

    【解决方案2】:

    我观察到UIDocumentPickerControllerUIViewController 的子类,其中UIImagepickerControllerUINavigationController 的子类。

    如果你尝试为 UIImagePickerController 设置tintColor of navBar ,你可以像imagePicker.navigationBar.tintColor = .red一样直接访问它,来到文档选择器,你不能直接访问navigationBar。你可以通过@访问它987654330@。这里navigationController is Optional.这就是我们无法直接访问导航栏并进行更改的原因。

    Apple 创建了一个带有文档选择器的应用程序。参考源码:Particles

    【讨论】:

    • 您的第一个建议不起作用,我无法全局设置色调。
    • 我已经更新了答案,如果我错了,请纠正我。
    猜你喜欢
    • 2013-10-26
    • 2015-07-16
    • 2015-11-19
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 2017-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多