/*CAAnimation
1.基础动画 CABasicAnimation
2.关键帧动画 CAKeyframeAnimation
3.转场动画 CATransition
4.动画组 CAAnimationGroup
*/
导入QuartzCore 头文件 和库
@interface ViewController ()
//声明一个图层的属性
@property (nonatomic,strong) CALayer *layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//创建一个图层
CALayer *layer = [CALayerlayer];
//设置layer的bounds 以自己为中心的坐标x,y都是00
layer.bounds = CGRectMake(0, 0, 100, 100);
//相对superlayer的位置
layer.position = CGPointMake(100, 100);
// layer.anchorPoint = CGPointMake(0, 0); 锚点和position是不同坐标系下的同一个位置
layer.backgroundColor = [UIColoryellowColor].CGColor;
//添加到视图的图层上
[self.view.layeraddSublayer:layer];
//赋值给自己的layer属性
self.layer = layer;
}
//通过触摸的方式演示动画
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[selfanimationScale];
}
- (void)animationScale{
//1.创建动画对象 通过类方法创建
CABasicAnimation *anim = [CABasicAnimationanimation];
//2.设置动画 :keyPath 决定了执行怎样的动画执行大小变化的动画
// anim.keyPath = @"backgroundColor";
anim.keyPath = @"bounds";
//bounds对应的是缩放 position对应的是平移 transform对应的是旋转
//tovalue是到达哪个点 byValue从增加多少值 fromValue 从哪个点开始移动
// anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];
/*创建一个矢量
anim.toValue = [NSValue valueWithCGVector:CGVectorMake(100, 100)];
*/
anim.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,50, 50)];
//动画执行时间
anim.duration = 3.0f;
//动画执行完毕后不移除动画
anim.removedOnCompletion =YES;//如果设置为NO 那么就要设置fillMode来规定动画结束后的状态
//动画状态 决定当前动画在非active时间段的行为 比如动画开始之前动画结束之后
// anim.fillMode = @"forwards";
//3.添加动画到图层上 key是用来标识动画的,应该是唯一的即使是nil
[self.layeraddAnimation:animforKey:nil];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}
@end