【问题标题】:Draw UIView and all its subview to Context将 UIView 及其所有子视图绘制到 Context
【发布时间】:2011-01-28 08:49:08
【问题描述】:

创建了一个 UIView 并在 UIView 中不断添加和删除小的 snow.png 以模拟下雪的效果。

然后我想将屏幕捕获为图像。

UIGraphicsBeginImageContext(self.uiviewPreview.bounds.size);
[self.uiviewPreview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

注意:self.uiviewPreview 是 UIView。

但我只能在保存的 jpg 中看到 UIview 中的图像。但是此时所有添加的子视图都没有保存。

我想知道renderInContext是否正确使用

【问题讨论】:

    标签: ios ios4


    【解决方案1】:

    这是正确的方法,它应该可以工作。

    请注意,该方法有一个很大的缺陷,它不能反映图层动画的实际状态(alpha、自动调整大小、重新定位等)。如果您在为图层设置动画的同时绘制图层,它将无法正常工作。

    【讨论】:

    • layer renderInContext 不做子视图,得自己做
    猜你喜欢
    • 1970-01-01
    • 2012-05-17
    • 2013-01-19
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多