2011-01-28 71 views
4

创建一个UIView并将小snow.png保持添加并移除到UIView以模拟降雪效果。绘制UIView及其全部子视图到上下文

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

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是否正确或不使用

回答

1

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

请注意,该方法有一个大缺陷,它不反映层动画(alpha,autoresizing,重新定位等)的实际状态。如果在制作动画时绘制图层,则无法工作。

+0

layer renderInContext不会做子视图,你必须自己做 – jjxtra 2013-03-15 22:18:13