How do I take a screenshot of a view which has transform?

有些话、适合烂在心里 提交于 2019-12-04 18:30:36
Aaron Brager

The Stack Overflow question "renderInContext:" and CATransform3D has more info, but the gist is:

QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer layers are not rendered. Additionally, layers that use 3D transforms are not rendered, nor are layers that specify backgroundFilters, filters, compositingFilter, or a mask values.

(from the CALayer docs).

More info is also available in this technical Q&A: http://developer.apple.com/library/ios/#qa/qa1703/_index.html

If your app is not going to the app store you can use the undocumented UIGetScreenImage API:

// Define at top of implementation file
CGImageRef UIGetScreenImage(void);

...

- (void)buttonPressed:(UIButton *)button
{
  // Capture screen here...
  CGImageRef screen = UIGetScreenImage();
  UIImage* image = [UIImage imageWithCGImage:screen];
  CGImageRelease(screen);

  // Save the captured image to photo album
  UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

(from John Muchow)

However, use of this API will make your app not get approved.

I have been unable to find any other workarounds.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!