开发者

Get size of an expanding circle in a CABasicAnimation at any point in time

开发者 https://www.devze.com 2023-02-24 00:32 出处:网络
I would like to know how I can get the diameter (or radius) o开发者_Go百科f an expanding circle animation at a at any point in time during the animation. I will end up stoping the animation right afte

I would like to know how I can get the diameter (or radius) o开发者_Go百科f an expanding circle animation at a at any point in time during the animation. I will end up stoping the animation right after I get the size as well, but figure I couldn't stop and remove it form the layer until I get the size of the circle.

For an example of how the expanding circle animation is implemented, it is a variation on the implementation shown in the addGrowingCircleAtPoint:(CGPoint)point method in the answer in the iPhone Quartz2D render expanding circle question.

I have tried to check various values on the layers, animation, etc but can't seem to find anything. I figure worse case I can attempt to make a best guess by taking the current time it is into its animation and use that to figure where it "should" be at based on its to and from size states. This seems like overkill for what I would assume is a value that is incrementing someplace I can just get easily.

Update:

I have tried several properties on the Presentation Layer including the Transform which never seems to change all the values are always the same regardless of what size the circle is at the time checked.


Okay here is how you get the current state of the an animation while it is animating.

While Rob was close he left out two pieces of key information.

First from the layer.presentationLayer.subLayers you have to get the layer you are animating on, which for me is the only sub layer available.

Second, from this sub layer you cannot just access the transform directly you have to do it by valueForKeyPath to get transform.scale.x. I used x because its a circle and x and y are the same.

I then use this to calculate the size of the circle at the time of the based on the values used to create the Arc.


I assume what you're trying to get to is the current CATransform3D, and that from that, you can get to your circle size.

What you want is the layer.presentationLayer.transform. See the CALayer docs for details on the presentationLayer. Also see the Core Animation Rendering Architecture.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号