-
-
Save Ilesh/81bf93ac09ec4fde01c3756956a9f7d9 to your computer and use it in GitHub Desktop.
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
class SpinView: UIView { | |
private var animating: Bool = false | |
private func spin(with options: UIViewAnimationOptions) { | |
// this spin completes 360 degrees every 2 seconds | |
UIView.animate(withDuration: 0.5, delay: 0, options: options, animations: {() -> Void in | |
self.transform = self.transform.rotated(by: .pi / 2) | |
}, completion: {(_ finished: Bool) -> Void in | |
if finished { | |
if self.animating { | |
self.spin(with: .curveLinear) | |
} else if options != .curveEaseOut { | |
// Last spin with easeOut | |
self.spin(with: .curveEaseOut) | |
} | |
} | |
}) | |
} | |
func startSpin() { | |
if !animating { | |
animating = true | |
spin(with: .curveEaseIn) | |
} | |
} | |
func stopSpin() { | |
animating = false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment