How to animate the pie charts developed using core-plot library?

前端 未结 3 479
刺人心
刺人心 2020-12-15 01:45

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.

Someo

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 01:59

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

    CPPieChart : CPPlot : CPAnnotationHostLayer : CPLayer : CALayer

    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.

提交回复
热议问题