UIImagePickerController |照片库出现但选择不起作用

时间:2017-07-12 22:13:07

标签: ios swift uiimagepickercontroller

我有一个UIImagePickerController在相机模式下工作正常,但在库模式下没有。显示照片库时,您可以滚动并选择取消,但点击时,不能选择相册。一直试图解决这个问题大约一个小时,但它没有用。

XCode 8.3.3 | iOS 10.3.2

需要添加适当的隐私,以下是我的简单演示代码。

非常感谢任何和所有帮助。

// Opens Photo Library
    func openPhotoLibrary() {
        if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
            let picker = UIImagePickerController()
            picker.delegate = self
            picker.allowsEditing = true
            picker.sourceType = .photoLibrary
            present(picker, animated: true, completion: nil)
        } else {
            UIAlertController.presentWith(title: "Error".localize(), message: "The photo library can not be accessed at this time.".localize(), on: self)
        }
    }

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        dismiss(animated: true, completion: nil)
        let image = info[UIImagePickerControllerOriginalImage] as! UIImage

        guard currentImage != "left" else {
            leftImage = image
            leftImageView.image = image
            return
        }

        guard currentImage != "right" else {
            rightImage = image
            rightImageView.image = image
            return
        }

        guard currentImage != "front" else {
            frontImage = image
            frontImageView.image = image
            return
        }
    }

问题链接:https://www.youtube.com/watch?v=wsKA994Sg88&feature=youtu.be

2 个答案:

答案 0 :(得分:0)

解决!

问题是由于我们用来解除键盘的UIView的扩展。你们中的许多人可能以前见过它。

extension UIView {
  // Dismisses Keyboard
  open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.endEditing(true)
  }
}

解决方案很简单,只需在super.touchesBegan(touches, with: event)之前添加self.endEditing(true)即可。

答案 1 :(得分:0)

好像你没有选择,但你是。问题是你需要在didFinishPickingMediaWithInfo中删除图像选择器

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
    {
           imagePicker.dismiss(animated: false, completion: nil)

    }