Created
February 14, 2019 18:39
-
-
Save nrlnishan/1ce8f513171904ac1641f7fe685adb57 to your computer and use it in GitHub Desktop.
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 { | |
| func shake() { | |
| let animation = CAKeyframeAnimation() | |
| animation.keyPath = "position.x" | |
| animation.values = [0, 10, -10, 10, -5, 5, -5, 0 ] | |
| animation.keyTimes = [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1] | |
| animation.duration = 0.4 | |
| animation.isAdditive = true | |
| self.layer.add(animation, forKey: "shake") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment