Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core-Plot iPhone Animation Examples

I've been looking into core-plot for the iPhone and I'm having trouble finding any examples of animation actually being used.

What I need to see is an example of how to use core-plots animation to add an extra plot to a graph when someone clicks a button.

If anyone can produce and example, or show me a link to one, that would be great.

Regards, Craig

like image 833
Craig Warren Avatar asked Jan 15 '10 11:01

Craig Warren


1 Answers

The official CPAnimation classes within Core Plot are just stubs right now. At some point, we'll enable the full functionality of those.

In the meantime, every visible element in Core Plot is a Core Animation CALayer, so you can animate these using existing Core Animation methods. For example, if you have a plot called dataSourceLinePlot (like in the test Core Plot iPhone application), you could start the plot off with an opacity of 0.0:

dataSourceLinePlot.opacity = 0.0f;
[graph addPlot:dataSourceLinePlot];

and then animate its opacity to fade it in:

CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimation.duration = 1.0f;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.fillMode = kCAFillModeForwards;
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
[dataSourceLinePlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];

This will fade in a new plot on an existing graph over a one second interval. You could also do something similar to animate it in from a side or use a transform to scale it up into position. CATransitions could also be used to achieve these kind of effects.

EDIT (1/17/2010): The Core Plot iPhone test application now contains an example of the fade-in animation described above.

like image 170
Brad Larson Avatar answered Nov 04 '22 18:11

Brad Larson