A helper function for animating CALayer with spring effect in Swift
Switch branches/tags
Clone or download
Evgenii Neumerzhitckii
Evgenii Neumerzhitckii Update
Latest commit 96a2887 Nov 23, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
SpringAnimationCALayerTests Update to Swift 3 Nov 23, 2016
.gitignore Initial commit Oct 31, 2014
README.md Update Nov 23, 2016
iiQ.swift Update to Swift 3 Nov 23, 2016


Animating CALayer with spring effect in iOS with Swift.

This demo app shows how to do spring animation on CALayer. Animation is similar to UIView's method animateWithDuration(_:delay:usingSpringWithDamping:...).


  1. Copy SpringAnimation.swift file to your project.
  2. Animate your CALayer's property by calling SpringAnimation.animate function.

For example, let's rotate a button's layer around its X axis in perspective:

let myCALayer = button.layer
var transform = CATransform3DIdentity
transform.m34 = -1.0/100.0
myCALayer.transform = CATransform3DRotate(transform, 0, 1, 0, 0)

                        keypath: "transform.rotation.x",
                        duration: 3.0,
                        usingSpringWithDamping: 0.7,
                        initialSpringVelocity: 1.7,
                        fromValue: M_PI,
                        toValue: 0,
                        onFinished: nil)

Rotate a button around X axis in iOS/Swift

Currently animation looks similar to UIView's method. But the duration, usingSpringWithDamping and initialSpringVelocity values are different from those in UIView's method.


Here is the formula that I am currently using for animation.


Spring animation formula

The Goal

The goal of this project is to make this CALayer's animation work exactly like UIView's for the same arguments.

Help me, Finn and Jake. You're my only hope.


Spring animation for CALayer in iOS with Swift