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"];
posted @ 2017-02-07 19:39  小眼奇遇记  阅读(192)  评论(0编辑  收藏  举报