- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_redLayer = [CALayer layer];
[_redLayer setFrame:CGRectMake(50, 50, 100, 100)];
[_redLayer setBackgroundColor:[UIColor redColor].CGColor];
[self.view.layer addSublayer:_redLayer];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//1
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
// animation.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
// animation.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)];
// [animation setDuration:2.0];
// animation.removedOnCompletion = NO; //这句必须有 不然回到原来的位置
// [animation setFillMode:kCAFillModeForwards];
// [self.redLayer addAnimation:animation forKey:nil];
//2
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
// animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0, 0, 1)];
// [animation setDuration:2.0];
// animation.removedOnCompletion = NO;
// [animation setFillMode:kCAFillModeForwards];
// [self.redLayer addAnimation:animation forKey:nil];
//3
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
// animation.toValue = @(M_PI_2);
// [animation setDuration:2.0];
// animation.removedOnCompletion = NO;
// [animation setFillMode:kCAFillModeForwards];
// [self.redLayer addAnimation:animation forKey:nil];
//等价于 (3和4)
//4
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
// animation.toValue = @(M_PI_2);
// [animation setDuration:2.0];
// animation.removedOnCompletion = NO;
// [animation setFillMode:kCAFillModeForwards];
// [self.redLayer addAnimation:animation forKey:nil];
//5
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale.xy"];
// animation.toValue = @(0.5);
// [animation setDuration:2.0];
// animation.removedOnCompletion = NO;
// [animation setFillMode:kCAFillModeForwards];
// [self.redLayer addAnimation:animation forKey:nil];
//等价于 (5和6)
//6
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
// animation.toValue = @(0.5);
// [animation setDuration:2.0];
// animation.removedOnCompletion = NO;
// [animation setFillMode:kCAFillModeForwards];
// [self.redLayer addAnimation:animation forKey:nil];
//7
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
// animation.toValue = @(100);
// [animation setDuration:2.0];
// animation.removedOnCompletion = NO;
// [animation setFillMode:kCAFillModeForwards];
// [self.redLayer addAnimation:animation forKey:nil];
}