Last active
June 23, 2022 08:34
-
-
Save jeffaburt/eac44d90924447c74560cfce304c4635 to your computer and use it in GitHub Desktop.
Allows any kind of UIView to start spinning in a 360 rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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