使用核心动画

时间:2015-10-12 06:00:01

标签: ios objective-c core-animation caanimation

我有基本的UILabel使用CACAKeyframeAnimation围绕一个完整的圆圈动画:

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path,nil, center.x,center.y, radius , DEGREES_TO_RADIANS(from_degree), DEGREES_TO_RADIANS((360+from_degree)), NO);

CAKeyframeAnimation *theAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

theAnimation.path = path;
CGPathRelease(path);

// set the animation properties
theAnimation.duration = duration;
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeBoth;
theAnimation.repeatCount = INFINITY;
theAnimation.calculationMode = kCAAnimationPaced;

[label.layer addAnimation:theAnimation forKey:@"position"];

有没有办法动画弧的半径变化并将该变化传播到沿路径移动的标签?

2 个答案:

答案 0 :(得分:-1)

 CGPathMoveToPoint(thePath, NULL, 100.f, 100.f);
 CGPathAddLineToPoint(thePath, NULL, 200.f, 100.f);
 CGPathAddArc(thePath, NULL, 100.f, 100.f, 100.f, 0.f, (360* M_PI)/180, NO);
 CGPathCloseSubpath(thePath);

你可以使用这个:)

答案 1 :(得分:-2)

 CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddArc(path, NULL, 100.f, 100.f, 100.f, 0.f, (360* M_PI)/180, NO);


    CAKeyframeAnimation *theAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    theAnimation.path = path;
    CGPathRelease(path);

    // set the animation properties
    theAnimation.duration = 3.0;
    theAnimation.removedOnCompletion = NO;
    theAnimation.fillMode = kCAFillModeBoth;
    theAnimation.repeatCount = INFINITY;
    theAnimation.calculationMode = kCAAnimationPaced;

    [self.lblTest.layer addAnimation:theAnimation forKey:@"position"];

试试这个..它会帮助你:))