2
votes

I am trying to scale in a core plot scatter plot (like a line graph) so that it scales in to view. CorePlot uses a normal CALayer to implement its plot.

I am using Core animation as follows to achieve this:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"affineTransform"];
animation.duration = 10;
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeForwards;
CGAffineTransform start = CGAffineTransformMakeScale(1, 0.1);
CGAffineTransform end = CGAffineTransformMakeScale(1, 1);
animation.fromValue = [NSValue valueWithCGAffineTransform:start];
animation.toValue = [NSValue valueWithCGAffineTransform:end];

[plot addAnimation:animation forKey:@"animation"];

The problem is this doesn't seem to work. This is the first time I am using core animation so I am thinking I am just doing something wrong?

EDIT OK so I found the issue I was using the wrong keypath.

I can get it to animate now but it looks wierd:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
...
animation.fromValue = [NSNumber numberWithFloat:0.1];
animation.toValue = [NSNumber numberWithFloat:1];

What I want to do is have the animation 'scale upwards' so it kind of stretches in to place. Right now it kind of grows out from the centre which is not what I want. Any idea how to achieve that?

1
What happens when you run it?Dustin
Nothing happens. As if there is no animation. I have just noticed that the 'affineTransform' member on CALayer is a method not a property, I guess the key path needs to be a property?Imran

1 Answers

0
votes

The transform is relative to the anchorPoint of the layer. You can change the anchor point to be at the bottom by setting it to (0.5, 1,0). Note that the layer also draws relative to the anchor point so it may change its position on screen when you change it. To position it where it should be you could either set the frame after changing the anchor point or set the position to the bottom (where it should scale from).