Skip to content

Instantly share code, notes, and snippets.

@takasurazeem
Forked from jeffaburt/UIView+Spinning.swift
Created June 23, 2022 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takasurazeem/da90b0b65eb677f781ee6c4fa6b92e68 to your computer and use it in GitHub Desktop.
Save takasurazeem/da90b0b65eb677f781ee6c4fa6b92e68 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