Created
January 10, 2012 15:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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