Skip to content

Instantly share code, notes, and snippets.

@NikhilManapure
Created July 19, 2017 11:59
Show Gist options
  • Save NikhilManapure/c6a3762aba9a3cb7b4388fd8a6331af7 to your computer and use it in GitHub Desktop.
Save NikhilManapure/c6a3762aba9a3cb7b4388fd8a6331af7 to your computer and use it in GitHub Desktop.
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