[iOS]How to make a “snapshot” of the current view’s state

I would suggest doing this:

Have a method that creates an image out of the contents of the view.

-(UIImage*) makeImage {

UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return viewImage;
}

Create a custom init method for your modal view, and also give your modalView an instance variable that can hold a UIImage something like…

- (id)initWithImage:(UIImage *)temp {
   myImage = temp;
}

Then in your modalView, perhaps in the viewDidLoad method, create a UIImageView and set the image to myImage

Hopefully this achieves what you are trying to do.

Leave a Comment