如何获取当前屏幕/ UIView的屏幕截图,包括图层

时间:2015-05-10 05:25:10

标签: ios objective-c uiview calayer avplayerlayer

在我的iOS应用程序中,我在myview.layer中添加了AVPlayerLayer作为子图层。根据我的要求,我必须截取这个特定视图的屏幕截图。如果我截取此特定视图的屏幕截图,则图层部分不包含在屏幕截图中。而且我也无法在Xcode预览选项中看到myview中的这个图层。任何人请提出你的建议来完成这个问题。

Ps:我已经尝试了reference中的所有方法。

但所有这些方法都不包括此CALayer。

已编辑内容:

我需要包含图层(AVPlayerLayer)的UIView的屏幕截图。有很多选项可以截取UIView的截图。但这些选项都没有帮助我。所以我发布了这个问题来解决我的问题。

1 个答案:

答案 0 :(得分:0)

来自This solution

Tim应该完美无缺(为方便起见,请在下面复制)。

#import "QuartzCore/QuartzCore.h" after you added the framework to your project. Then do:

UIGraphicsBeginImageContext(yourView.frame.size);
[[yourView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// The result is *screenshot
相关问题