Skip to content

Instantly share code, notes, and snippets.

View AD-Paladins's full-sized avatar
🔍
🍎📲

Andres D. Paladines AD-Paladins

🔍
🍎📲
View GitHub Profile
@AD-Paladins
AD-Paladins / UIView+Animations.swift
Last active January 22, 2018 20:13 — forked from mourad-brahim/UIView+Animations.swift
Shake animation with swift
extension UIView {
func shake(duration: CFTimeInterval) {
let translation = CAKeyframeAnimation(keyPath: "transform.translation.x");
translation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
translation.values = [-5, 5, -5, 5, -3, 3, -2, 2, 0]
let rotation = CAKeyframeAnimation(keyPath: "transform.rotation.z")
rotation.values = [-5, 5, -5, 5, -3, 3, -2, 2, 0].map {
(let degrees: Double) -> Double in
let radians: Double = (M_PI * degrees) / 180.0