我正在努力理解它是如何工作的,但是对我来说却很难。=)我有1个视图,有一个按钮和一个小的ImageView区域可供预览。该按钮触发imagepickercontroller,UIView将显示拾取的图像。没有错误,但是图像未显示在UIImageView区域中。
var imagePicker = UIImagePickerController() @IBOutlet var imagePreview : UIImageView @IBAction func AddImageButton(sender : AnyObject) { imagePicker.modalPresentationStyle = UIModalPresentationStyle.CurrentContext imagePicker.delegate = self self.presentModalViewController(imagePicker, animated: true) } func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!) { var tempImage:UIImage = info[UIImagePickerControllerOriginalImage] as UIImage imagePreview.image = tempImage self.dismissModalViewControllerAnimated(true) } func imagePickerControllerDidCancel(picker: UIImagePickerController!) { self.dismissModalViewControllerAnimated(true) }
您正在抓取UIImage具名,UIImagePickerControllerOriginalImage并且不存在此类图像。你注定要抓住UIImage用钥匙UIImagePickerControllerOriginalImage从editingInfo词典:
UIImage
UIImagePickerControllerOriginalImage
editingInfo
let tempImage = editingInfo[UIImagePickerControllerOriginalImage] as! UIImage