如何使用核心图库开发的饼图动画?

问题描述:

在iPhone应用程序Roambi中,显示的饼图可以动画显示为与用户一起旋转,就好像旋转光盘一样。我们可以持有并做很多事情。

In the iPhone application Roambi, the pie chart shown can be animated to rotate with the user as if rotating a disc. We can hold and do lot of stuff with that.

有人提到Roambi应用程序是使用核心图库开发的:

Someone mentioned that the Roambi app was developed using core-plot library:

什么图书馆使用Roambi app iPhone绘制图表?

如何操作使用Core plot开发的饼图?

How can I manipulate a pie chart developed using Core plot?

快速浏览一下Core Plot源代码,可以看出 CPPieChart 的继承如下所示:

A quick look at the Core Plot source code reveals that CPPieChart's inheritance looks like this:


CPPieChart CPPlot CPAnnotationHostLayer CPLayer CALayer

所以你可以看到,最后, CPPieChart 只是一个大量子类 CALayer 。我可能在这里完全不正确,但没有任何迹象表明这不能像任何其他 CALayer 一样动画。尝试使用以下代码将图层旋转360度:

So you can see that in the end, CPPieChart is just a heavily subclassed CALayer. I might be entirely incorrect here, but there's nothing that indicates that this can't be animated like any other CALayer. Try the following code to rotate the layer by 360 degrees:

CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"];
CATransform3D transform = CATransform3DMakeRotation(DegreesToRadians(360), 0, 0, 1);
rotation.toValue = [NSValue valueWithCATransform3D:transform];
rotation.duration = 10.0f;
[pieChart addAnimation:rotation forKey:@"rotation"];

如果你可以使这个工作,那么只需要读取加速度计的值并转换它们旋转角度。

If you can get this working then its just a matter of reading the values from the accelerometer and converting them to rotation angles.