1.storyboard上放一个RepView,在RepView上面放一个UIImageView,大小都和图片大小相同。
2.在RepView.m文件中加入下列方法
// 设置控件主层的类型
+ (Class)layerClass
{
return [CAReplicatorLayer class];
}
3.在控制器中加入如下代码
#import "ViewController.h"
#import "RepView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet RepView *repView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CAReplicatorLayer *layer = (CAReplicatorLayer *)_repView.layer;
layer.instanceCount = 2;
CATransform3D transform = CATransform3DMakeTranslation(0, _repView.bounds.size.height, 0);
// 绕着X轴旋转
transform = CATransform3DRotate(transform, M_PI, 1, 0, 0);
// 往下面平移控件的高度
layer.instanceTransform = transform;
// 透明度、红绿蓝的色差
layer.instanceAlphaOffset = -0.1;
layer.instanceBlueOffset = -0.1;
layer.instanceGreenOffset = -0.1;
layer.instanceRedOffset = -0.1;
}