核心动画忘得差很少了,特意翻出代码,从新写了一遍,如下是核心动画的步骤动画
@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]; }