Created
July 14, 2014 05:48
-
-
Save dnnta/662685df7e2cdca42c65 to your computer and use it in GitHub Desktop.
Pause and resume CABasicAnimations
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