首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CABasicAnimation保持恒定速度

CABasicAnimation保持恒定速度
EN

Stack Overflow用户
提问于 2012-08-16 14:37:00
回答 1查看 1.4K关注 0票数 1

我正在尝试用CABasicAnimation创建一个简单的动画,它将始终保持恒定的速度,即使动画必须行进的距离永远不会相同。到目前为止,这是我的代码,它正在滚动一个标签,它的大小总是变化的,但还不能保持恒定的速度。非常感谢您的帮助。

代码语言:javascript
复制
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.speed = 1.0f;

NSNumber *fromValue = [NSNumber numberWithFloat:self.mainLabel.frame.origin.x];
NSNumber *toValue = [NSNumber numberWithFloat:-self.mainLabel.frame.size.width - self.view.frame.size.height];
theAnimation.fromValue = fromValue;
theAnimation.toValue = toValue;
//theAnimation.duration = toValue.floatValue - fromValue.floatValue;//Not right.
theAnimation.repeatCount = 999;
theAnimation.autoreverses = NO;
[mainLabel.layer addAnimation:theAnimation forKey:@"animateLayer"];
EN

回答 1

Stack Overflow用户

发布于 2012-08-16 14:45:51

你有没有尝试添加:

代码语言:javascript
复制
 theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

在以下示例中

代码语言:javascript
复制
 theAnimation.speed = 1.0f;   

此函数用于设置动画的线性速度。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11981875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档