gpt4 book ai didi

ios - 将 UIView 及其所有 subview 绘制到 Context

转载 作者:可可西里 更新时间:2023-11-01 06:12:44 31 4
gpt4 key购买 nike

创建了一个 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中的图片。但是此时所有添加的 subview 都不会保存。

我想知道renderInContext是否正确使用

最佳答案

这是正确的方法,应该有效。

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

关于ios - 将 UIView 及其所有 subview 绘制到 Context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4826361/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com