Last active
April 30, 2018 07:18
-
-
Save mansi-27/ee7aa9bcf5cc9ac5eb0f2ffa99e48f23 to your computer and use it in GitHub Desktop.
Produce horizontal shake animation
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
| extension UIView { | |
| /// Produce horizontal shake animation | |
| func shakeHorizontally(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) { | |
| let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.x") | |
| animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) | |
| animation.repeatCount = count | |
| animation.duration = (duration)/TimeInterval(animation.repeatCount) | |
| animation.autoreverses = true | |
| animation.byValue = translation | |
| layer.add(animation, forKey: "shake") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment