views:

757

answers:

2

I have a UIView that has several UIImageViews as subviews. Each of these subviews has had different affine transform applied. I would like to take what amounts to a screen capture of my UIView, capturing it as a UIImage, or some other image representation.

The method I have tried already, rendering the layers to a CGContext with:

[view.layer renderInContext:UIGraphicsGetCurrentContext()];

doesn't preserve the positioning or other affine transformations of my subviews.

I would really appreciate a kick in the right direction.

+4  A: 

Try this:

UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Martin Gordon
You go it. I just had to change self.view.size to self.view.frame.size and use renderInContext.I'm not sure how I missed this, I guess the key phrase from Apple's docs is "Renders in the coordinate space of the layer."Thanks!
SooDesuNe
A: 

Hi, I have tried your code, Martin, but for me it crashes on the

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

line

However there is no error message in the console, nor warnings.

Subject78