How do you make a screenshot of an image made programmatically ? (swift)

时间:2015-12-10 02:00:03

标签: ios swift uiimageview uiimage screenshot

After retrieving an image from Parse and creating an UIImageView in the main storyboard, I did a screenshot of the view (DraggablePhoto) containing the UIImageView, by using the following scheme:

var view = MDCSwipeToChooseView(frame: self.DraggablePhoto.bounds, options: options)

    let imageori = UIGraphicsBeginImageContext(self.DraggablePhoto.bounds.size)
    let imageori1 = self.DraggablePhoto.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    var screenShot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    image = screenShot

    view.imageView.image = image

Problem is the UIImageView included in the DraggablePhoto view does not appear on the screenshot, knowing that the uiimageview includes a retrieved image from Parse...

My question is: Why is the screenshot not showing this image knowing that everything else is properly shown? How do you solve this problem? Please note I am a beginner.

EDIT: I found the solution to my problem. Just keep in mind that when you retrieve a file(i.e. picture) from Parse you need to make sure the screenshot function can access/be related with the line of code that matches the UIimageView with the image file... What I did is I called the screenshot func inside the .getDataInBackgroundWithBlock from Parse (not sure if this is a nice way to do it as I am still a beginner but it does the job on my screen)

0 个答案:

没有答案