容易或有效的方式将位图表示从一个视图复制到另一个视图? [英] Easy or efficient way to copy the bitmap representation from one view to another?

查看:182
本文介绍了容易或有效的方式将位图表示从一个视图复制到另一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有anViewA和anViewB。它们是带有很多子视图的纯UIView对象。我需要的只是位图表示或让我们说anViewA的图像复制到anViewB,所以anViewB看起来像anViewA(没有subView像anViewA)。

I have anViewA and anViewB. They're plain UIView objects with a lot of subviews. I need just the bitmap representation or lets say the "image" of anViewA copied over to anViewB, so that anViewB looks like anViewA (without having subviews like anViewA).

第一我试图使用-copy消息,但不幸的是UIView不符合NSCopying协议。

First I tried to use the -copy message, but unfortunately UIView doesn't conform to NSCopying protocol.

有一个技巧,使视觉的视觉副本

Is there another trick to make a "visual copy" of a view?

推荐答案

很简单的方法,但有一些限制(见 renderInContext description)

Very simple way, but with some limitation (see renderInContext description )

#import <QuartzCore/CALayer.h>

...

UIGraphicsBeginImageContext(anViewA.frame.size);
[anViewA.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * anImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
anViewB.image = anImage;

这篇关于容易或有效的方式将位图表示从一个视图复制到另一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆