1 // 2 // ViewController.m 3 // 04 CALayer的隐式动画 4 // 5 // Created by ZhuJiaCong on 16/4/18. 6 // Copyright © 2016年 wxhl. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 { 13 CALayer *_layer; 14 } 15 @end 16 17 @implementation ViewController 18 19 - (void)viewDidLoad { 20 [super viewDidLoad]; 21 22 //只有Layer不是View的根Layer时,才能使用隐式动画 23 // self.view.layer 24 25 //创建一个Layer 26 _layer = [CALayer layer]; 27 _layer.backgroundColor = [UIColor redColor].CGColor; 28 _layer.bounds = CGRectMake(0, 0, 100, 100); 29 _layer.position = self.view.center; 30 31 32 _layer.borderColor = [UIColor orangeColor].CGColor; 33 _layer.borderWidth = 5; 34 35 36 [self.view.layer addSublayer:_layer]; 37 38 39 40 } 41 42 43 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 44 45 //隐式动画 46 //当我们在设置Layer的某些属性时,系统会自动的给Layer添加动画 47 //动画的实现代码是在系统底层,无法对动画的配置进行修改 48 // _layer.transform = CATransform3DMakeRotation(M_PI, 0, 0, 1); 49 50 UITouch *touch = [touches anyObject]; 51 CGPoint location = [touch locationInView:self.view]; 52 _layer.position = location; 53 54 55 //查找文档 可以获取所有支持隐式动画的属性 56 //查找关键词 CALayer Animatable Properties 57 _layer.backgroundColor = [UIColor greenColor].CGColor; 58 //不透明度 59 _layer.opacity = 1; 60 _layer.borderColor = [UIColor purpleColor].CGColor; 61 _layer.borderWidth = 20; 62 } 63 64 - (void)didReceiveMemoryWarning { 65 [super didReceiveMemoryWarning]; 66 // Dispose of any resources that can be recreated. 67 } 68 69 @end