镜像UIView

我有一个透明背景的UIView和一些button。 我想捕捉视图的graphics,缩小它,并重画(镜像)在屏幕上的其他地方。 (在另一个视图之上。)button可以改变,所以它不是静态的。

什么是最好的方法来做到这一点?

查看以下WWDC会话的示例代码http://saveme-dot-txt.blogspot.com/2011/06/dynamic-view-reflection-using.html 。 它用

 CAReplicatorLayer 

反思,很容易实现,看起来非常顺利和令人印象深刻。

一般的想法是获得一个UIViewlayer来绘制自己的上下文,然后从中获取UIImage

 UIGraphicsBeginImageContext(view.frame.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

你还需要#import <QuartzCore/QuartzCore.h>

如果您确实不需要捕获绘图 (从您所描述的内容看来,似乎不太可能需要图像),请创build另一个视图实例并应用变换。 就像是…

 UIView* original [UIView alloc] initWithFrame:originalFrame]; UIView* copy = [[UIView alloc] initWithFrame:copyFrame]; // Scale down 50% and rotate 45 degrees // CGAffineTransform t = CGAffineTransformMakeScale(0.5, 0.5); copy.transform = CGAffineTransformRotate(t, M_PI_4); [someSuperView addSubview:original]; [someSuperView addSubview:copy]; // release, etc. 

我添加了旋转只是为了表明你可以用变换做各种不同的事情。