我可以在 CALayer 中为 NSBezierPath 设置动画吗?
我已经阅读了Apple的《Core Animation Cook Book》和《Core Animation Programming Guide》,但我不太清楚其中的一些细节。
我是否总是必须为整个 CALayer 制作动画,或者我可以为 CALayer 中的内容制作动画吗?
如果我在图层内绘制了 NSBezierPath 并且我想将其设置动画/移动到另一个位置,我该怎么做?您可以给我举一个例子吗?
I have read the Core Animation Cook Book and Core Animation Programming Guide from Apple, but I'm not quite sure about some of the details.
Do I always have to animate a complete CALayer, or can I animate stuff within a CALayer?
If I have drawn a NSBezierPath within a layer and I want to animate/move this to another position, how do I do that? Is there an example of this that you could point me to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您会将 CALayer 作为一个整体进行动画处理以获得最佳性能。如果您想要做的只是移动贝塞尔曲线路径的位置,您只需为 CALayer 的
position
或frame
属性设置动画即可。如果您想更改矢量路径的形状,我建议您查看新的 CAShapeLayer,您可以在其中使用图层上的
path
属性在一个 CGPath 和另一个 CGPath 之间设置动画。 Joe Ricioppo 有一些示例代码,您可以在此处查看。除此之外,如果您想更新图层的内容,而不是其基本属性(如位置、缩放、旋转等),则需要重新绘制图层。
Normally, you do animate the CALayer as a whole for best performance. If all you're looking to do is to shift the position of your Bezier path, you can simply animate the
position
orframe
properties of your CALayer.If you want to change the shape of a vector path, I'd recommend looking at the new CAShapeLayer, where you can animate between one CGPath and another by using the
path
property on the layer. Joe Ricioppo has some sample code you can look at for this here.Beyond that, you'll need to redraw the layer if you want to update its contents, rather than its base properties like position, scale, rotation, etc.