基于 UISlider 动作对 CATextLayer 进行动画处理
我在执行此动画时遇到一些问题。我感觉它可能存在一些问题,但我很难找到正确的方向。 我想在用户拖动 UISlider 控件时脉冲(放大和缩小)CATextLayer。
在 IBAction 方法中我有以下代码。我已检查以确保该方法确实被调用。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要为
contentScale
属性设置动画。 CATextLayer 中没有scale
属性。另外,我发现对
fontSize
进行动画处理似乎可以给我带来更多我想要的效果。它从中心对文本进行动画处理,而对contentScale
进行动画处理似乎是从角落之一进行动画处理。You want to animate the
contentScale
property. There is noscale
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 animatingcontentScale
seems to animate from one of the corners.