gpt4 book ai didi

iphone - 如何逐渐减慢旋转动画

转载 作者:行者123 更新时间:2023-11-28 22:40:06 25 4
gpt4 key购买 nike

我正在开发一个轮盘赌应用程序。其中,如果我点击中心按钮,轮子应该旋转几秒钟,然后它的速度应该逐渐变慢。如果有人知道,请以正确的方式指导我。

我可以以一定的速度旋转 imageView,但我很难逐渐降低轮子的速度。

旋转代码

CALayer *layer = container.layer;
CAKeyframeAnimation *animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 1.5f;
animation.cumulative = YES;
animation.repeatCount = 1;
animation.values = [NSArray arrayWithObjects: // i.e., Rotation values for the 3 keyframes, in RADIANS
[NSNumber numberWithFloat:0.0 * M_PI],
[NSNumber numberWithFloat:0.75 * M_PI],
[NSNumber numberWithFloat:1.5 * M_PI], nil];
animation.keyTimes = [NSArray arrayWithObjects: // Relative timing values for the 3 keyframes
[NSNumber numberWithFloat:0],
[NSNumber numberWithFloat:.5],
[NSNumber numberWithFloat:1.0], nil];
animation.timingFunctions = [NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn], // from keyframe 1 to keyframe 2
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]; // from keyframe 2 to keyframe 3
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[layer addAnimation:animation forKey:nil];

最佳答案

查看 CAKeyframeAnimation 的文档,您可以使用 timingFunctions 属性来添加缓动等

https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CAKeyframeAnimation_class/Introduction/Introduction.html

关于iphone - 如何逐渐减慢旋转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14770426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com