Sagar... Sagar... - 8 months ago 54
iOS Question

Taking screenshot of UIView which having subview with CATransform3DMakeRotation

I am trying to generate screenshot of UIView which having subview with

. Screenshot is generated but it doesn't contain Rotation.

Is it possible to achieve this?

Actual View:

enter image description here

ScreenShot Image

enter image description here

Using following call to Flip the view horizontally...

currentView.layer.transform = CATransform3DConcat(currentView.layer.transform,CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0f));

Code for taking screen shot

+ (UIImage *) imageWithView:(UIView *)view
CGSize screenDimensions = view.bounds.size;

// Create a graphics context with the target size
// (last parameter takes scale into account)
UIGraphicsBeginImageContextWithOptions(screenDimensions, NO, 0);

// Render the view to a new context
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

return img;


The "renderInContext" only works for Affine transform. So convert the 3D transform into affine transform like this

currentView.layer.affineTransform = CATransform3DGetAffineTransform(CATransform3DConcat(currentView.layer.transform,CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0f)));