基于 UISlider 动作对 CATextLayer 进行动画处理

发布于 2024-12-11 17:18:45 字数 615 浏览 3 评论 0原文

我在执行此动画时遇到一些问题。我感觉它可能存在一些问题,但我很难找到正确的方向。 我想在用户拖动 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角迷惘 2024-12-18 17:18:46

您想要为 contentScale 属性设置动画。 CATextLayer 中没有 scale 属性。

另外,我发现对 fontSize 进行动画处理似乎可以给我带来更多我想要的效果。它从中心对文本进行动画处理,而对 contentScale 进行动画处理似乎是从角落之一进行动画处理。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文