Skip to content

Instantly share code, notes, and snippets.

@TheCodedSelf
Created May 18, 2016 12:15
Show Gist options
  • Save TheCodedSelf/5d4965a01ecc295cfda864c9fe94c1f4 to your computer and use it in GitHub Desktop.
Save TheCodedSelf/5d4965a01ecc295cfda864c9fe94c1f4 to your computer and use it in GitHub Desktop.
import UIKit
extension UIView
{
func shake()
{
let shakeAngle = (5 * M_PI) / 360
let shakeRotation = CAKeyframeAnimation(keyPath: "transform.rotation")
shakeRotation.values = [0, shakeAngle, 0, -shakeAngle, 0]
shakeRotation.duration = 0.3
shakeRotation.repeatCount = 2
self.layer.addAnimation(shakeRotation, forKey: "shake")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment