CABasicAnimation真的很快?还是不行真的?对于圆形图

时间:2015-06-01 19:10:58

标签: ios calayer cashapelayer caanimation

您好我正在尝试为UIBezier / CGPath设置动画,它似乎正在快速移动。我试过一个似乎被忽略的缓和曲线。 虽然我觉得自己应该这样,但我并没有动画中风?看看它是什么样的。

Starts off Grey this is a separate layer with a highlight layer on top

Then the track layer is filled in with purple but it doesn't appear to follow the easing curve.

// Perform animation with information.
    -(CABasicAnimation*) percentageChangeAnimation:(CGFloat) percent withLineWidth:(CGFloat) lineWidth andHighlightLayer:(CAShapeLayer*) highlightLayer{
        // Address resize issue
        CGPoint center = [self centerOfGraphWithBounds:self.bounds];
        CGFloat radius =  [self radiusWithCenter:center andLineWidth:lineWidth];

        UIBezierPath* animateBeginValue = [self circularPathWithPercentage:0 andCenter:center andRadius:radius];
        UIBezierPath* animateEndValue = [self circularPathWithPercentage:percent andCenter:center andRadius:radius];

        CABasicAnimation* changeHighlight = [CABasicAnimation animationWithKeyPath:@"path"];

        // Property to animate uhh something odd going on... way to fast?
        changeHighlight.duration = 5.0;
        changeHighlight.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

        // begining path
        highlightLayer.path = [animateBeginValue CGPath];

        // CAST
        changeHighlight.fromValue = (id)[animateBeginValue CGPath];
        changeHighlight.toValue = (id)[animateEndValue CGPath];
        changeHighlight.fillMode = kCAFillModeForwards;

        // sync layer with model layer in a TODO
        // Don't remove revert to the model layer from the presentation layer.
        changeHighlight.removedOnCompletion = NO;

        [highlightLayer addAnimation:changeHighlight forKey:@"change"];

        // Id key for the animation
        return changeHighlight;
    }

从灰色开始,这是一个单独的图层,顶部有一个高光层 然后轨道图层用紫色填充,但它似乎不符合缓和曲线

它几乎就像忽略了CATiming和持续时间一样。 根据我的理解,路径可以动画。

编辑已解决:

// Perform animation with information.
-(CABasicAnimation*) percentageChangeAnimation:(CGFloat) percent withLineWidth:(CGFloat) lineWidth andHighlightLayer:(CAShapeLayer*) highlightLayer{
    // Address resize issue
    CGPoint center = [self centerOfGraphWithBounds:self.bounds];
    CGFloat radius =  [self radiusWithCenter:center andLineWidth:lineWidth];

    /**
    UIBezierPath* animateBeginValue = [self circularPathWithPercentage:0 andCenter:center andRadius:radius];
    UIBezierPath* animateEndValue = [self circularPathWithPercentage:percent andCenter:center andRadius:radius];
    **/


    CABasicAnimation* changeHighlight = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    changeHighlight.duration = 2.0f;
    changeHighlight.fromValue = [NSNumber numberWithFloat:0.0f];
    changeHighlight.toValue = [NSNumber numberWithFloat:1.0f];


    /**
    CABasicAnimation* changeHighlight = [CABasicAnimation animationWithKeyPath:@"path"];


    // begining path

    highlightLayer.path = [animateBeginValue CGPath];
    // Property to animate uhh something odd going on...
    changeHighlight.duration = 5.0;
    changeHighlight.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    // CAST
    changeHighlight.fromValue = (id)[animateBeginValue CGPath];
    changeHighlight.toValue = (id)[animateEndValue CGPath];

  **/


    changeHighlight.fillMode = kCAFillModeForwards;

    // Don't remove revert to the model layer from the presentation layer.
    changeHighlight.removedOnCompletion = NO;
    highlightLayer.strokeColor = [[UIColor flatPurpleColor] CGColor];
    [highlightLayer addAnimation:changeHighlight forKey:@"change"];

    // Id key for the animation
    return changeHighlight;
}

现在我只需要调整图表百分比的计算。不管怎样,谢谢

1 个答案:

答案 0 :(得分:0)

上面的解决方案,你需要使用笔画路径结束并开始。