Skip to content

Instantly share code, notes, and snippets.

@naoyashiga
Created August 18, 2015 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save naoyashiga/af38a6b6d2722ab104e9 to your computer and use it in GitHub Desktop.
Save naoyashiga/af38a6b6d2722ab104e9 to your computer and use it in GitHub Desktop.
Implicit and Explicit Bounce Animation Button
extension UIButton {
func playImplicitBounceAnimation() {
let bounceAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
bounceAnimation.values = [1.0 ,1.4, 0.9, 1.15, 0.95, 1.02, 1.0]
bounceAnimation.duration = NSTimeInterval(0.5)
bounceAnimation.calculationMode = kCAAnimationCubic
layer.addAnimation(bounceAnimation, forKey: "bounceAnimation")
}
func playExplicitBounceAnimation() {
let bounceAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
var values = [Double]()
let e = 2.71
for t in 1..<100 {
let value = 0.6 * pow(e, -0.045 * Double(t)) * cos(0.1 * Double(t)) + 1.0
values.append(value)
}
bounceAnimation.values = values
bounceAnimation.duration = NSTimeInterval(0.5)
bounceAnimation.calculationMode = kCAAnimationCubic
layer.addAnimation(bounceAnimation, forKey: "bounceAnimation")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment