Shake a View

suggest change
extension UIView {
    func shake() {
        let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
        animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
        animation.duration = 0.6
        animation.values = [-10.0, 10.0, -7.0, 7.0, -5.0, 5.0, 0.0 ]
        layer.add(animation, forKey: "shake")
    }
}

This function can be used to draw attention to a specific view by shaking it a bit.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents