Skip to content

Instantly share code, notes, and snippets.

@dnnta
Created July 14, 2014 05:48
Show Gist options
  • Save dnnta/662685df7e2cdca42c65 to your computer and use it in GitHub Desktop.
Save dnnta/662685df7e2cdca42c65 to your computer and use it in GitHub Desktop.
Pause and resume CABasicAnimations
-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment