Created
February 22, 2018 18:01
-
-
Save mansi-27/74d5ea132ff042bfcf3d1a88a2b8a354 to your computer and use it in GitHub Desktop.
Produce vertical 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 vertical shake animation | |
| func shakeVertically(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) { | |
| let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.y") | |
| 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