项目以使用来控制动画,例如暂停、复苏继续等待,看看代码:(非常easy实现)
-(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中我们加入了多个动画,(不是组合动画),相同easy实现动画的暂停、恢复,方法就是为每一个动画层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];
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。