Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created February 28, 2021 15:35
Show Gist options
  • Save fredriccliver/08cf3153f6a24369997c6e0454fb642c to your computer and use it in GitHub Desktop.
Save fredriccliver/08cf3153f6a24369997c6e0454fb642c to your computer and use it in GitHub Desktop.
extension UIView{
// ...
func shake(){
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.duration = 0.6
animation.values = [-20.0, 20.0, -20.0, 20.0, -10.0, 10.0, -5.0, 5.0, 0.0 ]
self.layer.add(animation, forKey: "shake")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment