Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Pausing / resuming animation #29

Closed
iwasrobbed opened this issue Dec 9, 2017 · 0 comments
Closed

Pausing / resuming animation #29

iwasrobbed opened this issue Dec 9, 2017 · 0 comments
Labels

Comments

@iwasrobbed
Copy link
Owner

Question

From an issue via email:

How do I pause and resume an animation (i.e. one that's in the middle of animating)?

Answer

Read Apple's technical note here: https://developer.apple.com/library/content/qa/qa1673/_index.html

e.g.

func pauseAnimation() {
  var pausedTime = layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
  layer.speed = 0.0
  layer.timeOffset = pausedTime
}

func resumeAnimation() {
  var pausedTime = layer.timeOffset
  layer.speed = 1.0
  layer.timeOffset = 0.0
  layer.beginTime = 0.0
  let timeSincePause = layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
  layer.beginTime = timeSincePause
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant