Is there an issue with updating a CALayer position while the layer is paused?

青春壹個敷衍的年華 提交于 2019-12-03 14:51:23

There's not an issue with updating aCALayerposition whilst it's paused. Naturally however it will give the flicker that you mention. That's because you are updating the layer's position mid animation.

Don't forget that creating aCABasicAnimationand adding it to aCALayerdoesn't change the layer's settings. It creates an animation using the layer, but it doesn't change the layer.

That's why after the animation has finished, you'll see the layer back in exactly the same position it was before.

Because of this, if you are animating a layer from A to B, if you want the layer to appear at B after the animation has finished, you'll need this delegate callback:

- (void)animationDidStart:(CAAnimation *)theAnimation
{ 
    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanTrue
                     forKey:kCATransactionDisableActions];
    myLayer.position = targetPosition;    
    [CATransaction commit];
}

Yep, it'sanimationDidStart. If we did it usinganimationDidStopthen you would see another flicker. The layer would be in the animation's end position of B, then you'd see a flicker of it at A, and then you'd see it at B again.

UsinganimationDidStartwe set the position to be thetargetPosition, i.e.B because that's where we want to see it on completion.

Now, regarding QA1673, what you are doing with this is setting the animation speed to zero, and getting a timestamp of the currentCACurrentMediaTime(). On resume, you put the speed back to normal, and apply any offsets incurred during the pause time.

This all seems pretty confusing until you get the hang of it. Could I recommend some reading and videos?

Definitely have a read of Core Animation Rendering Architecture.

Videos that are highly recommended are:

WWDC 2010 Sessions 424 and 425 Core Animation in Practice Parts 1 and 2

WWDC 2011 Session 421 Core Animation Essentials

and

Developer Videos Session 716 Core Animation Techniques for iPhone and Mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!