IOS/Swift 暂停和恢复图层动画

2022-08-25  本文已影响0人  ZM_微笑向阳

开始图层动画的代码:

//mySuperLayer父图层
  CFTimeInterval pausedTime = [self.mySuperLayer timeOffset];
 if (pausedTime > 0)//在暂停后才能使用
 {
     self.mySuperLayer.speed = 1.0;
     self.mySuperLayer.timeOffset = 0.0;
     self.mySuperLayer.beginTime = 0.0;
     CFTimeInterval timeSincePause = [self.mySuperLayer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
     self.mySuperLayer.beginTime = timeSincePause;
 }

暂停图层动画的代码:

CFTimeInterval pausedTime = [self.mySuperLayer convertTime:CACurrentMediaTime()     fromLayer:nil];
self.mySuperLayer.speed = 0.0;
self.mySuperLayer.timeOffset = pausedTime;
上一篇下一篇

猜你喜欢

热点阅读