我希望将背景(UIImageView)与上层UIView(MyView)结合,然后截取合并图像的屏幕截图。我正在使用下面的代码,但背景完全涵盖了我的UIView ......有什么建议吗?
UIImageView *ViewToBeAddedAsBackground = BackgroundImageView;
ViewToBeAddedAsBackground.frame = CGRectMake(0,0,770,410);
[MyView addSubview:ViewToBeAddedAsBackground];
UIGraphicsBeginImageContext(MyView.frame.size);
[MyView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *MyView_IMAGE = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(MyView_IMAGE, nil, nil, nil);
答案 0 :(得分:1)
这是因为您要将ViewToBeAddedAsBackground
添加为subView
的{{1}},因此它通常会覆盖它,您应该做的是反之,添加yourView
为子视图yourView
然后
ViewToBeAddedAsBackground
您可以尝试以下操作,具体取决于您当前的视图可行性
[insertSubview:ViewToBeAddedAsBackground.layer renderInContext:UIGraphicsGetCurrentContext()];