Created
July 19, 2017 11:59
-
-
Save NikhilManapure/c6a3762aba9a3cb7b4388fd8a6331af7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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