核心动画忘得差不多了,特地翻出代码,重新写了一遍,以下是核心动画的步骤
@interface ViewController ()
@property (nonatomic,weak)CALayer *layer;
@end
- (void)viewDidLoad {
[super viewDidLoad];
// 核心动画的步骤
// 创建图层
CALayer *layer = [CALayer layer];
// 赋值属性
self.layer = layer;
// 图层的背景颜色
layer.backgroundColor = [UIColor redColor].CGColor;
// frame
layer.frame = CGRectMake(100, 100, 100, 100);
// 添加到layer
[self.view.layer addSublayer:layer];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CABasicAnimation *anim = [CABasicAnimation animation];
// 更改layer的哪个属性进行核心动画,scale代表缩放,rotation代表旋转
anim.keyPath = @"transform.scale";
// 改变什么样的值
anim.toValue = @0.5;;;
// 设置动画的执行次数,MAXFLOAT最大的执行次数,默认为0
anim.repeatCount = 1;
// 把核心动画添加到图层
[self.layer addAnimation:anim forKey:nil];
}