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

开始图层动画的代码: 

   //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;

 

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

例子下载:https://github.com/yoimhere/ZJLoadView/archive/master.zip

 

  

你可能感兴趣的:(swift)