iOS 13全屏UIImagePickerController吗?

时间:2019-11-21 18:34:02

标签: ios uiviewcontroller ios13 uimodalpresentationstyle

我正在更新一个支持iOS 13的应用程序,目前(其中一项)要求是将所有模式UIViewControllers都转换回UIModalPresentationStyle.fullScreen,但是UIImagePickerController确实可以似乎不尊重我传递的值,并且在选择照片时始终处于“卡片视图”中,而在选择视频时始终处于全屏状态。

有没有办法使两个ViewController具有与卡片或全屏相同的外观?

1 个答案:

答案 0 :(得分:0)

不以这个为答案,只是提供帮助。这是我用Xcode 11.2编写的针对iOS 13.0的工作代码:

class ViewController: UIViewController {

    let imagePicker = UIImagePickerController()
    var btnOpenImage = UIButton()

    override func viewDidLoad() {
        super.viewDidLoad()

        btnOpenImage.translatesAutoresizingMaskIntoConstraints = false
        btnOpenImage.backgroundColor = UIColor.red
        btnOpenImage.setTitle("Show Picker", for: .normal)
        btnOpenImage.addTarget(self, action: #selector(showImagePicker), for: .touchUpInside)
        view.addSubview(btnOpenImage)

        btnOpenImage.widthAnchor.constraint(equalToConstant: 180).isActive = true
        btnOpenImage.heightAnchor.constraint(equalToConstant: 80).isActive = true
        btnOpenImage.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        btnOpenImage.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    }
}
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    @objc func showImagePicker() {
        imagePicker.allowsEditing = false
        imagePicker.sourceType = .photoLibrary
        imagePicker.modalPresentationStyle = .fullScreen
        present(imagePicker,
                animated: true,
                completion: nil)
    }
    @objc internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        dismiss(animated: true, completion: nil)
    }
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: false, completion: nil)
    }
}

它并没有做很多,但是它会全屏显示东西。它是从一个更大的项目中提取的,并在运行13.1和13.2的iPad Mini上进行了测试。还在iPhone 11 Pro模拟器中进行了测试。

有一件事,当我将NSPhotoLibraryUsageDescription键添加到info.plist时,它从不实际上弹出了任何东西!?!