CABasicAnimation动画

来源:互联网 发布:云盘 网站维护源码 编辑:程序博客网 时间:2024/05/17 01:43

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    _redLayer = [CALayerlayer];

    [_redLayersetFrame:CGRectMake(50,50, 100,100)];

    [_redLayersetBackgroundColor:[UIColorredColor].CGColor];

    [self.view.layeraddSublayer:_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];

}

0 0
原创粉丝点击