CAShapeLayer Animation (Bogen von 0 bis Endgröße)

Ich habe einCAShapeLayer in dem ein Bogen mit hinzugefügt wirdUIBezierPath. Ich habe ein paar Posts (tatsächlich einen) hier auf stackoverflow gesehen, aber keiner schien mir die Antwort zu geben. Wie im Titel erwähnt, möchte ich einen Bogen animieren (ja, für ein Tortendiagramm).

Wie kann man eine Animation von einem "leeren" Bogen zu einem voll ausgefahrenen erstellen? Ein bisschen wie ein gebogener Fortschrittsbalken. Ist es wirklich unmöglich, dies zu tun?CoreAnimation?

So "mache" ich den Lichtbogen. Oh und ignoriere die Kommentare und Berechnungen, da ich es gewohnt bin, den Einheitskreis im Gegenuhrzeigersinn zu drehen und Apfel im Uhrzeigersinn. Die Bögen sehen gut aus, ich brauche nur Animation:

    //Apple's unit circle goes in clockwise rotation while im used to counter clockwise that's why my angles are mirrored along x-axis
    workAngle = 6.283185307 - DEGREES_TO_RADIANS(360 * item.value / total);

    //My unit circle, that's why negative currentAngle
    [path moveToPoint:CGPointMake(center.x + cosf(outerPaddingAngle - currentAngle) * (bounds.size.width / 2), center.y - (sinf(outerPaddingAngle - currentAngle) * (bounds.size.height / 2)))];

    //Apple's unit circle, clockwise rotation, we add the angles
    [path addArcWithCenter:center radius:120 startAngle:currentAngle endAngle:currentAngle + workAngle clockwise:NO];

    //My unit circle, counter clockwise rotation, we subtract the angles
    [path addLineToPoint:CGPointMake(center.x + cosf(-currentAngle - workAngle) * ((bounds.size.width / 2) - pieWidth), center.y - sinf(-currentAngle - workAngle) * ((bounds.size.height / 2) - pieWidth))];

    //Apple's unit circle, clockwise rotation, addition of angles
    [path addArcWithCenter:center radius:120 - pieWidth startAngle:currentAngle + workAngle endAngle:currentAngle - innerPaddingAngle clockwise:YES];

    //No need for my custom calculations since I can simply close the path
    [path closePath];

    shape = [CAShapeLayer layer];
    shape.frame = self.bounds;
    shape.path = path.CGPath;
    shape.fillColor = kRGBAColor(255, 255, 255, 0.2f + 0.1f * (i + 1)).CGColor; //kRGBAColor is a #defined

    [self.layer addSublayer:shape];


    //THIS IS THE PART IM INTERESTED IN
    if (_shouldAnimate)
    {
        CABasicAnimation *pieAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
        pieAnimation.duration = 1.0;
        pieAnimation.removedOnCompletion = NO;
        pieAnimation.fillMode = kCAFillModeForwards;
        //from and to are just dummies so I dont get errors
        pieAnimation.fromValue = [NSNumber numberWithInt:0]; //from what
        pieAnimation.toValue = [NSNumber numberWithFloat:1.0f]; //to what

        [shape addAnimation:pieAnimation forKey:@"animatePath"];
    }

Antworten auf die Frage(3)

Ihre Antwort auf die Frage