0

I am developing a roulette wheel app. In which if i tap on center button wheel should rotate for few seconds and then its speed should get slow down gradually. Please guide me in right way if anyone knows.

I could able to rotate an imageView with some uniform speed but i am facing struggle to slow down the wheel's speed gradually.

Rotation code

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];
thavasidurai
  • 1,972
  • 1
  • 26
  • 51

1 Answers1

2

Looking at the docs for CAKeyframeAnimation, you have the timingFunctions property to add easing etc

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

robhayward
  • 392
  • 3
  • 10