OC动画CABasicAnimation

//1.创建动画
    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"bounds"];
    //1.1设置动画执行时间
    anima.duration=2.0;
    //1.2设置动画执行完毕后不删除动画
    anima.removedOnCompletion=YES;
    //1.3设置保存动画的最新状态
    //kCAFillModeForwards保存动画的最新状态  kCAFillModeBackwards保存最开始状态
    anima.fillMode=kCAFillModeForwards;
    //1.4修改属性,执行动画
    anima.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
    //2.添加动画到layer
    [redView.layer addAnimation:anima forKey:nil];

 //1.创建动画
    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"transform"];
    //1.1设置动画执行时间
    anima.duration=2.0;
    //1.2修改属性,执行动画
    anima.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2+M_PI_4, 1, 1, 0)];
    //1.3设置动画执行完毕后不删除动画
    anima.removedOnCompletion=NO;
    //1.4设置保存动画的最新状态
    anima.fillMode=kCAFillModeBackwards;
    anima.repeatCount = 1000;
    
    //2.添加动画到layer
    [redView.layer addAnimation:anima forKey:nil];

 

CABasicAnimation *anima=[CABasicAnimation animation];
    //1.1告诉系统要执行什么样的动画
    anima.keyPath=@"position";
    //设置通过动画,将layer从哪儿移动到哪儿
    anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
    anima.toValue=[NSValue valueWithCGPoint:CGPointMake(300, 300)];
    anima.duration = 1.0f;
    //1.2设置动画执行完毕之后不删除动画
    anima.removedOnCompletion=YES;
    //1.3设置保存动画的最新状态
    anima.fillMode=kCAFillModeForwards;
    //设置代理
    anima.delegate=self;
    //2.添加核心动画到layer
    [redView.layer addAnimation:anima forKey:nil];

CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount =  MAXFLOAT;
     [redView.layer addAnimation:rotationAnimation forKey:nil ];
 //透明动画
         CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
         opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
         opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
         opacityAnim.removedOnCompletion = YES;
    
 //缩放动画
         CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
         scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
         scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5, 0.5, 0.1)];
原文地址:https://www.cnblogs.com/hualuoshuijia/p/9946773.html