CALayer帧动画

CALayer帧动画

帧动画


        _sunLayer = [[CALayer alloc]init];
        _sunLayer.contents = (id)[UIImage imageNamed:@"sun"].CGImage;
        _sunLayer.bounds = CGRectMake(0, 0, 40, 40);
        _sunLayer.position = CGPointMake(100, 200);
        [self.layer addSublayer:_sunLayer];
        
        CAKeyframeAnimation *keyframe = [CAKeyframeAnimation animationWithKeyPath:@"position"];//帧动画-位移
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, _sunLayer.position.x, _sunLayer.position.y);//移动到起始点
        CGPathAddEllipseInRect(path, NULL, CGRectMake(100, 200, 200, 200));
        keyframe.path = path;//路径
        [keyframe setCalculationMode:kCAAnimationPaced];//加上不会停顿
        keyframe.duration = 2.0;//时间
        keyframe.repeatCount = HUGE_VAL;//重复-无限重复
        [_sunLayer addAnimation:keyframe forKey:@"fsfsf"];
原文地址:https://www.cnblogs.com/ritian/p/6375684.html