获取 CABasicAnimation 中任意时间点的扩展圆的大小
我想知道如何在动画期间的任何时间点获取扩展圆形动画的直径(或半径)。在获得尺寸后,我最终也会停止动画,但我认为在获得圆圈的尺寸之前,我无法停止并将其从图层中删除。
有关如何实现扩展圆形动画的示例,它是 iPhone Quartz2D 渲染扩展圆问题。
我尝试检查图层、动画等的各种值,但似乎找不到任何东西。我认为更糟糕的情况是,我可以尝试通过将当前时间放入其动画中来尝试做出最佳猜测,并使用它来根据其大小状态来确定它“应该”位于的位置。对于我所认为的在我可以轻松获得的地方递增的值来说,这似乎有点矫枉过正。
更新:
我已经尝试了表示层上的几个属性,包括变换,它似乎永远不会改变,所有值始终相同,无论检查时圆圈的大小如何。
I would like to know how I can get the diameter (or radius) of 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这是在动画播放时获取动画当前状态的方法。
虽然罗布很接近,但他遗漏了两条关键信息。
首先,您必须从 layer.presentationLayer.subLayers 获取要进行动画处理的图层,这对我来说是唯一可用的子图层。
其次,从这个子层你不能直接访问变换,你必须通过 valueForKeyPath 来获取transform.scale.x。我使用 x 是因为它是一个圆,并且 x 和 y 相同。
然后,我使用它根据用于创建圆弧的值来计算圆的大小。
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.
我假设您想要获取的是当前的
CATransform3D
,并且从中您可以获取圆的大小。您想要的是
layer.presentationLayer.transform
。有关presentationLayer 的详细信息,请参阅CALayer
文档。另请参阅核心动画渲染架构。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 theCALayer
docs for details on the presentationLayer. Also see the Core Animation Rendering Architecture.