本文介绍了Flatten UIViews子视图到UIImage iPhone 3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UIView有几个UIImageViews作为子视图。这些子视图中的每一个都应用了不同的仿射变换。我想要占用我的UIView的屏幕捕获,捕获它作为UIImage或一些其他图像表示。
我已经尝试的方法,渲染层到CGContext:
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
不会保留我的子视图的定位或其他仿射变换。
$ b $解决方案
请尝试以下操作:
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I have a UIView that has several UIImageViews as subviews. Each of these subviews has had different affine transform applied. I would like to take what amounts to a screen capture of my UIView, capturing it as a UIImage, or some other image representation.
The method I have tried already, rendering the layers to a CGContext with:
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
doesn't preserve the positioning or other affine transformations of my subviews.
I would really appreciate a kick in the right direction.
解决方案
Try this:
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这篇关于Flatten UIViews子视图到UIImage iPhone 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!