0

I have this code that rotates my imageview but when I press my pause button I want the rotation speed to be 0. How would I do that?

@IBAction func playButtonL(sender: AnyObject) {

    rotation.toValue = NSNumber(double: M_PI * 2)
    rotation.duration = 2
    rotation.cumulative = true
    rotation.repeatCount = FLT_MAX
    self.leftCircleImageView.layer.addAnimation(rotation, forKey: "rotationAnimation")
}


@IBAction func pauseButtonR(sender: AnyObject) {


}
coding22
  • 689
  • 1
  • 7
  • 28
  • it works but I have one problem is that it goes back to its original position when it stops. I want it so that it stops at the position its at. – coding22 Apr 05 '16 at 06:34

1 Answers1

1

To Reduce time of animation you can use

rotation.duration = 2

To stop reset it's state default you can use

cabasicanimation.removedOnCompletion = NO;

cabasicanimation.fillMode = kCAFillModeForwards;

Answer credits and reference :

CABasicAnimation resets to initial value after animation completes

Hope it helps! let me know if you need any further help.

Community
  • 1
  • 1
Milan V.
  • 697
  • 1
  • 6
  • 22
  • I was putting the code in the wrong button. I tried all 3 lines of code and the circle keeps rotating. – coding22 Apr 05 '16 at 06:46
  • Its not stopping at all. I did rotation.fillMode = kCAFillModeForwards and the other two lines of code and it doesnt stop at its final position. – coding22 Apr 05 '16 at 07:14
  • circle still rotates for some reason. If I add the line self.leftCircleImageView.layer.removeActionWithKey(rotation, "rotationAnimation") it stops but resets to the original position. – coding22 Apr 05 '16 at 07:18