【发布时间】:2015-04-28 23:10:01
【问题描述】:
我在我的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/
我不确定自己做错了什么。
【问题讨论】:
-
不需要给动画一个
toValue吗?值应以弧度表示。使用DEGREES_TO_RADIANS(<value in degrees>)。 -
你是说这个
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI)) -
#define DEGREES_TO_RADIANS(degrees) (M_PI * (degrees) / 180.0) -
从您的演示链接中,旋转图像似乎是错误的。 @EricSkroch 下面的回答更有意义。使用 corePlot 类附带的动画来为适当的属性设置动画。
-
你似乎知道 corePlot。你能给我举个例子吗?我不知道我做错了什么
标签: ios objective-c animation core-plot pie-chart