How to get image from UIImagePickerController and Pass to next VC

后端 未结 6 1998
心在旅途
心在旅途 2021-01-15 22:41

I select a photo from PhotoLibrary and How can I achieve below tasks

In this case, I am using Swift. I need to reconstruct the image in the next VC either thru :

6条回答
  •  萌比男神i
    2021-01-15 23:16

    Use the imagePickerController didFinishPickingImage instead:

    1 & 2)

        // Class variable
        var image: UIImage?
        ...
        func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { 
    
            self.image = image
            picker.dismissViewControllerAnimated(true, completion: { (finished) -> Void in
                // Perform your segue to your next VC
            })
        }
    
       override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    
    // One of the two segue.destinationViewController.isKindOfClass(YourDestinationViewController) {
        if segue.identifier == "Your Destination View Controller Identifier" {
                let destinationViewController = segue.destinationViewController as! YourDestinationViewController
                destinationViewController.image = self.image
            }
        }
    

    3)

    image.size.height
    image.size.width
    

提交回复
热议问题