0

I have an animation with 5.0 second duration. While an animation is being played, i pause it at 2.0 second and do some other things (moving to other viewcontroller, push, pop...). And then i back to this viewcontroller and continue animation from second 2.0. I made it work smooth with timeOffSet = 2.0, but still have an issue : It has 2 seconds surplus, that is the first 2 second of an animation.....How can i remove it ?

Animation with timeOffSet process:

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Lowji
  • 3
  • 3

1 Answers1

0

Duplicated answer

-(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;
}