我看了很多解决方案,遗憾的是,这对我没有用。我用这段代码创建了一个imagePickerController:
@IBAction func takePhoto(sender: UIButton) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.allowsEditing = false
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, _didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
imageView.contentMode = .ScaleAspectFit
imageView.image = pickedImage
dismissViewControllerAnimated(true, completion: nil)
}
但是我在相机上拍摄的图像仍未显示在imageView中。我还导入了正确的代理人。当我尝试将imageView.image打印到控制台时,它返回nil
。我做错了什么?
答案 0 :(得分:1)
Please try this code. Hope it will help you.
func cameraPhoto(){
imagePicker.allowsEditing = true
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.cameraCaptureMode = .Photo
imagePicker.cameraDevice = .Front;
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage
}
Thanks