Skip to content

Instantly share code, notes, and snippets.

@larsacus
Created January 10, 2012 15:46
Show Gist options
  • Save larsacus/1589708 to your computer and use it in GitHub Desktop.
Save larsacus/1589708 to your computer and use it in GitHub Desktop.
Pauses and resumes all CA Animations on a CALayer - from http://developer.apple.com/library/ios/#qa/qa1673/_index.html
-(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