为什么这不是动画?

Why is this not animating?

我在我的 xcode 项目中实现了 corePlot。我有一个要制作动画的饼图。这是我的代码:

- (void)configureChart
{
    CPTGraph *graph = self.hostView.hostedGraph;

    CPTPieChart *pieChart = [[CPTPieChart alloc] init];
    pieChart.dataSource = self;
    pieChart.delegate = self;
    pieChart.pieRadius = (self.hostView.bounds.size.height * 0.7) / 2;
    pieChart.startAngle = M_PI_4;
    pieChart.sliceDirection = CPTPieDirectionClockwise;

    [graph addPlot:pieChart];

这是我试过的:

    CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rotation.removedOnCompletion = YES;
    rotation.fromValue = [NSNumber numberWithFloat:0.0f];
    rotation.duration = 1.0f;
    rotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    rotation.delegate = self;
    [pieChart addAnimation:rotation forKey:@"rotation"];
}

当我 运行 应用程序时,它没有动画。我做错了什么,我该如何解决?

更新 1

我尝试了以下方法:

[CPTAnimation animate:pieChart property:@"startAngle" from:pieChart.startAngle to:pieChart.endAngle duration:1.0];

没有达到预期的效果。图表会显示一秒钟,然后消失。

更新 2

我正在尝试获得这种效果:http://jsfiddle.net/ozgr1wfx/

我不确定我做错了什么。

不要为图层变换设置动画。改为动画起始角度。否则,任何标签和其他注释都将随绘图一起旋转。

来自 Plot 图库 示例应用程序:

[CPTAnimation animate:piePlot
             property:@"startAngle"
                 from:CPTFloat(M_PI_2)
                   to:CPTFloat(M_PI_4)
             duration:0.25];

如评论中所述,角度以弧度表示(pi 弧度 = 180 度)。

感谢@RoryMcKinnel,我终于明白了。

[CPTAnimation animate:pieChart property:@"endAngle" from:pieChart.startAngle + M_PI * 2 to:pieChart.startAngle  duration:2.0];

这将使您的饼图像这样动画化:http://jsfiddle.net/ozgr1wfx/

再次。感谢@RoryMcKinnel 让我走上了正确的轨道!