iOS Animations - kgleong/software-engineering GitHub Wiki

Animations

Animated UIImages

References

Keyframe Animations

UIView.animateKeyframes(withDuration: 2, delay: 0, options: [.repeat, .autoreverse, .calculationModePaced], animations: {
        UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0) {
            spinner.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI * 2)/3)
            spinner.backgroundColor = UIColor.blue
        }
        UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0) {
            spinner.transform = CGAffineTransform(rotationAngle: 2*CGFloat(M_PI * 2)/3)
            spinner.backgroundColor = UIColor.green
        }
        UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0) {
            spinner.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI * 2))
            spinner.backgroundColor = UIColor.red
        }
    }, completion: nil)

References

References

Spring Damping

(void)animateWithDuration:(NSTimeInterval)duration
                  delay:(NSTimeInterval)delay
 usingSpringWithDamping:(CGFloat)dampingRatio
  initialSpringVelocity:(CGFloat)velocity
                options:(UIViewAnimationOptions)options
             animations:(void (^)(void))animations
             completion:(void (^)(BOOL finished))completion;
parameter description values
duration How long the animation should take, in seconds. if <= 0, no animation will be applied
dampingRatio Amount of bouncing desired. Use 1 to smoothly decelerate with no oscillation. Values closer to 0 will increase oscillation/bouncing. The higher the value, the faster the oscillations will cease.
velocity The spring's initial velocity. The damping ratio will proportionally decrement this value until the velocity reaches 0. Higher values will increase the oscillations speed.

References

References