本文介绍了Swift - UIImagePickerController - 如何使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力了解它是如何工作的,但对我来说这很难。 =)
我有1个视图,有一个按钮和一个小的ImageView区域可供预览。
按钮触发imagepickercontroller,UIView将显示选中的图像。
没有错误但是图像没有显示在UIImageView区域中。

I am trying hard to understand how this works, but it's pretty hard for me. =)I have 1 view, there is one button and one small ImageView area for preview.The button triggers imagepickercontroller, and the UIView will display picked image.There is no error but the image doesn't show in the UIImageView area.

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 名为 UIImagePickerControll erOriginalImage 并且没有这样的图像。您打算从 editingInfo UIImagePickerControllerOriginalImage 键获取 UIImage c $ c>字典:

You're grabbing a UIImage named UIImagePickerControllerOriginalImage and there exists no such image. You're meant to grab the UIImage with the key UIImagePickerControllerOriginalImage from the editingInfo dictionary:

let tempImage = editingInfo[UIImagePickerControllerOriginalImage] as! UIImage

这篇关于Swift - UIImagePickerController - 如何使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:08