本文介绍了用它的孩子渲染UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIView ,它有一个图像和一些按钮作为其子视图。我想使用 renderInContext 或其他方法获取它的快照图像。

I have a UIView that has an image and some buttons as its subviews. I'd like to get a "snapshot" image of it using renderInContext, or other method.

[clefView.layer renderInContext:mainViewContentContext];

如果我传递给我 UIView (如上面)然后我得到一个空白的位图。没有子项被渲染到位图中。

If I pass it my UIView (as above) then I get a blank bitmap. None of the children are rendered into the bitmap.

如果我传递了作为图像的子视图,那么我得到一个该位图的图像,并且毫不奇怪,没有它的兄弟(按钮)。

If I pass it the child view that is the image, then I get an image of that bitmap, and, unsurprisingly, none of its siblings (buttons).

我有点希望 renderInContext 将图像及其所有可见子项渲染成位图。有没有人有任何想法如何做到这一点?

I was sort of hoping that renderInContext would take the image and all it's visible children and render it into a bitmap. Has anyone have any ideas how to do this?

推荐答案

尝试这样的事情:

UIGraphicsBeginImageContext(clefView.bounds.size);
[clefView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

这篇关于用它的孩子渲染UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 23:33