复制层示例(图片倒影)

Posted on 2016-07-12 18:59  柠檬片  阅读(102)  评论(0)    收藏  举报
 1 #import "VCView.h"
 2 
 3 @implementation VCView
 4 
 5 
 6 //返回当前layer的类型
 7 +(nonnull Class)layerClass{
 8    return [CAReplicatorLayer class];
 9 }
10 
11 
12 
13 /*
14 // Only override drawRect: if you perform custom drawing.
15 // An empty implementation adversely affects performance during animation.
16 - (void)drawRect:(CGRect)rect {
17     // Drawing code
18 }
19 */
20 
21 @end
自定义的VCView
 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 @property (weak, nonatomic) IBOutlet UIImageView *imageV;
 5 
 6 @end
 7 
 8 @implementation ViewController
 9 
10 - (void)viewDidLoad {
11     [super viewDidLoad];
12     
13     // Do any additional setup after loading the view, typically from a nib.
14 
15     NSLog(@"%@",[self.view.layer class]);
16     
17     CAReplicatorLayer *repL =   (CAReplicatorLayer *)self.view.layer;
18     repL.instanceCount = 2;
19     //复制出来的子层,它都是绕着复制层锚点进行旋转(复制层的锚点就是复制层的中点)(重要).
20     repL.instanceTransform = CATransform3DMakeRotation(M_PI*0.6, 1, 0, 0);
21     
22     
23     repL.instanceRedOffset -= 0.1;
24     repL.instanceGreenOffset -= 0.1;
25     repL.instanceBlueOffset -= 0.1;
26     repL.instanceAlphaOffset -= 0.1;
27 
28     
29     
30 
31 }
32 
33 - (void)didReceiveMemoryWarning {
34     [super didReceiveMemoryWarning];
35     // Dispose of any resources that can be recreated.
36 }
37 
38 @end
ViewController.m

//详见图片倒影示例代码