绘制直线的动画(Quartz 2D?)
您将如何在 iPhone 上的 UIView 中对线条绘制进行动画处理? 这可能吗? 它可以绘制,但可以轻松对其进行动画处理,使其看起来像是手绘的吗?
How would you go about animating the drawing of a line in a UIView on the iPhone? Is this possible? It can be drawn but can it easily be animated so it appears to be hand drawn?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有内置的方法可以做到这一点。 您必须重复重绘线条,使用计时器回调在起点和终点之间进行插值以使视图无效并触发重绘。 当然,重绘必须绘制视图区域中的所有内容,这可能会很慢。
如果我想在一段时间内绘制一系列线条,我会做的是有两个子视图 - 它们将覆盖相同的区域,而顶部的将具有透明背景。 让顶部的一个只绘制我当前正在制作动画的线条,完成后,在下部视图中绘制它的完整长度。 然后重复,为顶视图中的下一行设置动画。
There's no built-in way to do this no. You'd have to redraw the line repeatedly, interpolating between the start and end points using a timer callback to invalidate the view and trigger a redraw. Of course the redraw would have to draw everything in the area of the view bring redrawn which is potentially slow.
What I would do if I had a series of lines I wanted to draw over a period of time is to have two subviews - they would cover the same area and the top one would have a transparent background. Have the top one draw just the line that I am currently animating and when it's finished, draw the full length of it in the lower view. Then repeat, animating the next line in the top view.
借助新的 API,您可以使用 CGPath 的
StrokeEnd
属性轻松完成此操作。您可以在此处阅读更多详细信息:对线条进行动画处理的最简单方法是什么?
With the new API you can do that easily, using
strokeEnd
property of CGPath.You can read more details here: What's the easiest way to animate a line?