我在superView中有一组UIViews,每个UIView里面都有一个UIImageView。 UIImageViews已经应用了CGAffineTransformation,如果它们变得比UIView大,UIView会变得更大以适应UIImageView。
终极目标:使用所有UIImageViews +背景图像保存图像。
到目前为止,我可以使用以下方法成功访问每个UIImageView:
for (id obj in self.view.subviews) {
if ([obj isKindOfClass:[UIView class]] && [((UIView *)obj).subviews.firstObject isKindOfClass:[UIImageView class]]) {
UIImageView *view = ((UIImageView *)((UIView *)obj).subviews.firstObject);
}
}
如何将这些图像与背景图像合并并保留其所有属性。
答案 0 :(得分:2)
要实现此目的,您可以使用- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates
。
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:NO];
//The merged image.
UIImage * mergedBackground = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Remove superviews as they are no longer required.
[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];