Animate CATextLayer based on UISlider action

946 views Asked by At

I am having some problems getting this animation to execute. I have a feeling there are probably a few problems with it, but am having trouble finding the right direction. I would like to pulse (scale up and down) a CATextLayer while the user is dragging a UISlider control.

Inside the IBAction method I have the following code. I have checked to make sure that the method is actually being called.

CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"scale"];
pulse.fromValue = [NSNumber numberWithFloat:1.0];
pulse.toValue = [NSNumber numberWithFloat:1.2];
pulse.duration = 1;
pulse.repeatCount = HUGE_VALF;
pulse.autoreverses = YES;
pulse.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.symbolLayer addAnimation:pulse forKey:nil]; 

I have noticed that the method is called repeatedly very fast, Im not sure if this preventing the animation from going, or there is a problem with the animation block itself.

1

There are 1 answers

1
Ferruccio On BEST ANSWER

You want to animate the contentScale property. There is no scale property in CATextLayer.

Alternatively, I've found that animating fontSize seems to give me more of the effect I was looking for. It animates the text from the center, whereas animating contentScale seems to animate from one of the corners.