【问题标题】:How to slow down a rotate animation gradually如何逐渐减慢旋转动画
【发布时间】:2013-02-08 10:25:28
【问题描述】:

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

我可以以某种匀速旋转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];

【问题讨论】:

    标签: iphone ios objective-c image-rotation


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复。是否有任何示例代码来应用timingFunctions
    猜你喜欢
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多