【问题标题】:Draw image from subview into superview将图像从子视图绘制到父视图
【发布时间】:2014-02-02 01:57:26
【问题描述】:

我提前道歉,这是一个很难解释的问题。 本质上,我正在尝试在 Photoshop 中执行与合并图层等效的操作,其中背景图像与所有其他图像合并,并获得 Leo 指出的新背景图像。

我在 superView 内部有一组 UIView,每个 UIView 内部都有一个 UIImageView。 UIImageView 应用了 CGAffineTransformations,如果它们变得比 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);

        }
    }

如何将这些图像与背景图像组合并保留它们的所有属性。

【问题讨论】:

  • 仍然不清楚您要达到的目标。是不是类似于 Photoshop 中的“合并图层”,将背景图像与所有其他图像合并,然后得到一个新的背景图像?
  • 是的,没错。谢谢你

标签: ios cocoa-touch uiview uiimageview cgaffinetransform


【解决方案1】:

为此,您可以使用- (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)];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多