我的imageView无法显示我使用UIImagePicker选择的图片。
这是所有代码:
@IBAction func addImage(_ sender: Any) {
if !didShowCamera {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
if UIImagePickerController.isSourceTypeAvailable(.camera) {
imagePicker.sourceType = .camera
imagePicker.cameraCaptureMode = .photo
} else {
imagePicker.sourceType = .photoLibrary
}
self.present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
print(image)
self.jobImage.image = takenImage
self.takenImage = image
didShowCamera = true
self.dismiss(animated: true, completion: nil)
}
有什么办法解决吗?
答案 0 :(得分:1)
使用调度主队列
DispatchQueue.main.async {
self.jobImage.image = takenImage
self.takenImage = image
}
答案 1 :(得分:0)
我猜在分配给图像视图时takenImage
为零,您需要先将图像分配给takenImage
,然后再设置为图像视图。请更新类似的方法,
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
print(image)
self.takenImage = image
self.jobImage.image = takenImage
didShowCamera = true
self.dismiss(animated: true, completion: nil)
}
答案 2 :(得分:0)
替换
['a', 'e', 'i', 'o', 'u']
与
map
并检查是否在info.plist中添加了隐私照片库访问权限。
中的详细信息