ios - 选择/拍摄后如何将图像从相机/相机胶卷传递到新 View ?

标签 ios swift camera uiimagepickercontroller

我已经在我的应用程序中添加了一个相机和照片库,但我想要做的是当有人选择相机、拍照并选择它时,我希望它将用户引导到一个新的 View Controller 和在那里显示图像而不是在按钮所在的当前 View 上?

我在 Google 上进行了搜索,但没有发现任何清晰或快速的内容,而且由于我不了解 ObjC,所以我不确定我所看到的是否正确!

下面是我当前的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


@IBAction func Camera(sender: AnyObject) {

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
    imagePicker.allowsEditing = false
    self.presentViewController(imagePicker, animated: true, completion: nil)
    }
}


@IBAction func Images(sender: AnyObject) {

    let imageLoad = UIImagePickerController()
    imageLoad.delegate = self
    imageLoad.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    imageLoad.allowsEditing = false


    self.presentViewController(imageLoad, animated: true, completion: nil)
}


func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image:UIImage, editingInfo: [String : AnyObject]?) {

    self.dismissViewControllerAnimated(true, completion: nil)

最佳答案

根据上面的回答,你试图将图像设置为 ImageView ,当你应该尝试将图像设置为 ImageView 的图像时,所以,它应该是:

func viewDidLoad() {
    super.viewDidLoad()

    // Because the self.image is an optional var, you need to unwrap it
    if let image = self.image {
        self.imageView.image = self.image
    } 
}

关于ios - 选择/拍摄后如何将图像从相机/相机胶卷传递到新 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34229507/

相关文章:

ios - Xcode 7.3.1 在 MacOS Sierra Beta 5 上崩溃

ios - 将 UISlider 添加到 UIView

swift - 如何使用子类来遵守协议(protocol)

ios - 快速从字符串中剥 ionic 字符串

android - getDefaultDisplay().getRotation();总是返回相同的值

iOS 应用因 Facebook SDK 中的 IDFA 而被拒绝

ios - 打开 iOS 应用程序后,未调用 "continue userActivity:"方法 - Firebase 动态链接

swift - 无法分配给属性 : 'self' is immutable, 我知道如何修复但需要理解

android - 开始录制后相机变暗

iphone - 单击 iPhone 应用程序中的表格 View 单元格打开相机