利用Layer做一些动画的时候,如果我们一直创建重新生成核心动画的时候。系统开销太大了。我们以后再次碰到这些问题的时候尽量利用系统给予我们的资料
https://developer.apple.com/library/ios/qa/qa1673/_index.html去重用这些动画
#pragma mark - #pragma mark ---------------layerAnimalPause -(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; layer.timeOffset = 0.0; layer.beginTime = 0.0; CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime; layer.beginTime = timeSincePause; }
附上github上的demo: https://github.com/fuunnyy/Test_pauseLayer