Skip to content

Instantly share code, notes, and snippets.

@nrlnishan
Created February 14, 2019 18:39
Show Gist options
  • Select an option

  • Save nrlnishan/1ce8f513171904ac1641f7fe685adb57 to your computer and use it in GitHub Desktop.

Select an option

Save nrlnishan/1ce8f513171904ac1641f7fe685adb57 to your computer and use it in GitHub Desktop.
Shake Animation
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