Skip to content

Instantly share code, notes, and snippets.

@mansi-27
Created February 22, 2018 18:01
Show Gist options
  • Select an option

  • Save mansi-27/74d5ea132ff042bfcf3d1a88a2b8a354 to your computer and use it in GitHub Desktop.

Select an option

Save mansi-27/74d5ea132ff042bfcf3d1a88a2b8a354 to your computer and use it in GitHub Desktop.
Produce vertical shake animation
extension UIView {
/// Produce vertical shake animation
func shakeVertically(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) {
let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.y")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.repeatCount = count
animation.duration = (duration)/TimeInterval(animation.repeatCount)
animation.autoreverses = true
animation.byValue = translation
layer.add(animation, forKey: "shake")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment