Kodeco Forums

Video Tutorial: Intermediate iOS Animation Part 6: Layer Springs

In this video tutorial, you'll create spring animations for your layers.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3270-intermediate-ios-animation/lessons/7

There is an issue in the starter project for this lesson if youโ€™re running it on Swift 3

on line 190 ViewController extension needs to be implement CAAnimationDelegate protocol. You also needs to remove the override for animationDidStop so you end up with this:

extension ViewController: CAAnimationDelegate {
  
   func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
    guard let name = anim.value(forKey: "name") as? String,
      let layer = anim.value(forKey: "layer") as? CALayer else {
        return
    }
    
    if name == "form" {
      let bounce = CABasicAnimation(keyPath: "transform.scale")
      bounce.fromValue = 1.2
      bounce.toValue = 1.0
      bounce.duration = 0.5
      layer.add(bounce, forKey: nil)
    } else if name == "cloud" {
      layer.frame.origin.x = -layer.frame.size.width
      delay(seconds: 0.1, completion: {
        self.animateCloud(layer)
      })
    }
  }
}

also change all the delegates for your animation to self instead of self as! CAAnimationDelegate
This should happen on line 180 for cloudMove and flyRight

indeed the code in these projects isnโ€™t iOS10 compatible, but an update for this course is in the works: https://videos.raywenderlich.com/schedule