ios animation的暂停pause、恢复resume
-(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; }
如果在一个view中我们添加了多个动画,(不是组合动画),同样容易实现动画的暂停、恢复,方法就是为每个动画层layer调用上面的方法,比如我的方法如下,我用的是三个单独动画的组合效果,就是如下调用的
-(void)stopAnimation; { NSLog(@"停止动画"); //[_customView.layer removeAllAnimations]; [self pauseLayer:_customView1.layer]; [self pauseLayer:_customView2.layer]; [self pauseLayer:_customView3.layer]; } -(void)resumeAnimation { [self resumeLayer:_customView1.layer]; [self resumeLayer:_customView2.layer]; [self resumeLayer:_customView3.layer]; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。