图像未显示且UIImagePickerController未显示

时间:2017-05-17 07:44:49

标签: ios swift xcode swift3

我在collectionViewCell中有这段代码:

lazy var logoImageView: UIImageView = {
    let imageView = UIImageView()
    imageView.image = UIImage(contentsOfFile: "yeee")
    imageView.layer.cornerRadius = 25
    imageView.translatesAutoresizingMaskIntoConstraints = false
    imageView.contentMode = .scaleAspectFit

    imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView)))
    imageView.isUserInteractionEnabled = true

    return imageView
}()

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])  {
    picker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
    var selectedImageFromPicker: UIImage?

    if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage {

        selectedImageFromPicker = editedImage

    } else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
        selectedImageFromPicker = originalImage
    }

    if let selectedImage = selectedImageFromPicker {
        logoImageView.image = selectedImage
    }
}

当我构建应用程序时,图像名称" yeee"当我使用imagePickerController选择它时,显示,也不显示图像。我知道这个问题已被提出,但没有一个答案解决了我的问题。

当我改变时:     imageView.image = UIImage(contentsOfFile: "yeee")imageView.image = UIImage(named: "yeee"),图片名为" yeee"出现,但从UIImagePickerController中选择的图像不会显示。我该怎么办?

更新:

func handleSelectProfileImageView() {
    let picker = UIImagePickerController()
    picker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
    picker.allowsEditing = true
    present(picker, animated: true, completion: nil)
}

0 个答案:

没有答案