CABasicAnimation动画

- (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];

 

//等价于 (34)

    

    //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];

    

 //等价于 (56)

    

    //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];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值