Created
February 28, 2021 15:35
-
-
Save fredriccliver/08cf3153f6a24369997c6e0454fb642c to your computer and use it in GitHub Desktop.
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(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