Skip to content

Instantly share code, notes, and snippets.

@jeffaburt
Last active June 23, 2022 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffaburt/eac44d90924447c74560cfce304c4635 to your computer and use it in GitHub Desktop.
Save jeffaburt/eac44d90924447c74560cfce304c4635 to your computer and use it in GitHub Desktop.
Allows any kind of UIView to start spinning in a 360 rotation
import UIKit
extension UIView {
func startSpinning() {
let spinAnimation = CABasicAnimation()
spinAnimation.fromValue = 0
spinAnimation.toValue = M_PI * 2
spinAnimation.duration = 2.5
spinAnimation.repeatCount = Float.infinity
spinAnimation.removedOnCompletion = false
layer.addAnimation(spinAnimation, forKey: "transform.rotation.z")
}
func stopSpinning() {
layer.removeAllAnimations()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment