CABasicAnimation

缩放
    CABasicAnimation *scaleAnimation = [[CABasicAnimation alloc] init];
    scaleAnimation.keyPath = @"transform.scale"; // 设置动画的方式
    scaleAnimation.fromValue = [NSNumber numberWithInteger:1]; // 起点
    scaleAnimation.toValue = [NSNumber numberWithInteger:2]; // 终点
    scaleAnimation.duration = 0.6f; // 设置动画的时间
    scaleAnimation.repeatCount = 3.5; // 设置动画的次数
    scaleAnimation.autoreverses = YES; // 返回原始状态是否动画方式
    scaleAnimation.removedOnCompletion = NO;
    scaleAnimation.fillMode = kCAFillModeForwards;
    [scaleLayer addAnimation:scaleAnimation forKey:@"scale"]; // 添加动画
透明度

CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];//key 为opacity

animation.fromValue=[NSNumber numberWithFloat:1.0];

animation.toValue=[NSNumber numberWithFloat:0.0];

animation.autoreverses=YES;

animation.duration=time;

animation.repeatCount=FLT_MAX;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;
横向移动
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

animation.toValue=x;

animation.duration=time;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;
旋转
CATransform3D rotationTransform  = CATransform3DMakeRotation(degree, 0, 0,direction);

CABasicAnimation* animation;

animation = [CABasicAnimation animationWithKeyPath:@"transform"];

animation.toValue= [NSValue valueWithCATransform3D:rotationTransform];

animation.duration= dur;

animation.autoreverses= NO;

animation.cumulative= YES;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

animation.repeatCount= repeatCount;

animation.delegate= self;
组合
CAAnimationGroup *groupAnnimation = [CAAnimationGroup animation];
    groupAnnimation.duration = 2;
    groupAnnimation.autoreverses = YES;
    groupAnnimation.animations = @[moveAnimation, scaleAnimation, rotateAnimation];
    groupAnnimation.repeatCount = MAXFLOAT;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容