CABasicAnimation 从 fromValue 继续

发布于 2024-12-29 12:21:25 字数 585 浏览 0 评论 0原文

在完成 toValue 过程后,我如何继续 UIImageView transform.translation.x 动画。例如:当按按钮#1:从 1 到 55,按按钮#2 从 55 到 110....并且如果它在按钮#2的位置,然后单击按钮#5,然后从55*2到55*5。

- (void)animateArrow{
CABasicAnimation *theAnimation;


theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.4;
theAnimation.repeatCount=1;
theAnimation.toValue=[NSNumber numberWithFloat:50];

[buttonArrow.layer setValue:theAnimation.toValue forKey:theAnimation.keyPath];
[buttonArrow.layer addAnimation:theAnimation forKey:@"transform.translation.x"];

}

How can i continue a UIImageView transform.translation.x animation after it completed a toValue Process.for example:when press the button#1:from 1 to 55,press button#2 from 55 to 110....and if it at the position of button#2,and you click button#5,then from 55*2 to 55*5.

- (void)animateArrow{
CABasicAnimation *theAnimation;


theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.4;
theAnimation.repeatCount=1;
theAnimation.toValue=[NSNumber numberWithFloat:50];

[buttonArrow.layer setValue:theAnimation.toValue forKey:theAnimation.keyPath];
[buttonArrow.layer addAnimation:theAnimation forKey:@"transform.translation.x"];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

德意的啸 2025-01-05 12:21:25

您应该考虑在数组中沿着动画路径提供多个点,如下所示:

CAKeyframeAnimation *downMoveAnimation;
downMoveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
downMoveAnimation.duration = 12;
downMoveAnimation.repeatCount = 1;
downMoveAnimation.values = [NSArray arrayWithObjects:           
                             [NSNumber numberWithFloat:20], 
                             [NSNumber numberWithFloat:220], 
                             [NSNumber numberWithFloat:290], nil]; 
downMoveAnimation.keyTimes = [NSArray arrayWithObjects:     
                               [NSNumber numberWithFloat:0], 
                               [NSNumber numberWithFloat:0.5], 
                               [NSNumber numberWithFloat:1.0], nil]; 

downMoveAnimation.timingFunctions = [NSArray arrayWithObjects:
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],        // from keyframe 1 to keyframe 2
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]; // from keyframe 2 to keyframe 3

downMoveAnimation.removedOnCompletion = NO;
downMoveAnimation.fillMode = kCAFillModeForwards;

希望这有效。

基本动画和关键帧动画之间的主要区别在于关键帧允许您指定路径上的多个点。

You should think about providing multiple points along the animation path in an array like this:

CAKeyframeAnimation *downMoveAnimation;
downMoveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
downMoveAnimation.duration = 12;
downMoveAnimation.repeatCount = 1;
downMoveAnimation.values = [NSArray arrayWithObjects:           
                             [NSNumber numberWithFloat:20], 
                             [NSNumber numberWithFloat:220], 
                             [NSNumber numberWithFloat:290], nil]; 
downMoveAnimation.keyTimes = [NSArray arrayWithObjects:     
                               [NSNumber numberWithFloat:0], 
                               [NSNumber numberWithFloat:0.5], 
                               [NSNumber numberWithFloat:1.0], nil]; 

downMoveAnimation.timingFunctions = [NSArray arrayWithObjects:
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],        // from keyframe 1 to keyframe 2
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]; // from keyframe 2 to keyframe 3

downMoveAnimation.removedOnCompletion = NO;
downMoveAnimation.fillMode = kCAFillModeForwards;

Hope this works.

The main difference between basic animation and key-frame animation is that Key-frame allows you to specify multiple points along the path.

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