您的位置:首页 > 其它

How to pause the animation of a layer tree

2013-09-13 10:26 417 查看
From: http://www.devdiv.com/how_to_pause_the_animation_of_a_layer_tree-blog-21666-51864.html


Q: How do I pause all animations in a layer tree?

A: In order to pause animations in a layer tree, you can take advantage of the fact that a
CALayer
conforms to the
CAMediaTiming
protocol.
The
CAMediaTiming
protocol defines, among other things, a speed with which its timeline progresses, which you can use to pause all animations on the target
layer. Listing 1 demonstrates how you can do this.

Listing 1 Pause and Resume animations.

-(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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐