0

The following code was pulled from another SO answer, but is it possible to delay the start of this CAKeyframeAnimation animation similar to how UIView's animateWithDuration offers a delay property?

Based on the class docs, the CAKeyframeAnimation class doesn't seem to contain a delay property.

    let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
    animation.duration = 1.0
    animation.repeatCount = 2
    animation.values = [-10, 10, -10, 10, -5, 5, -2, 2, 0]
    view.layer.addAnimation(animation, forKey: "shake")
Crashalot
  • 33,605
  • 61
  • 269
  • 439

1 Answers1

5

You can try this thing. Trying to delay start time of the animation.

animation.beginTime = CACurrentMediaTime() + 5.0   // change to your custom delay.
Vishnu gondlekar
  • 3,896
  • 21
  • 35