你如何在IOS中创建SVG路径的动画?(How do you animate an SVG path in IOS?)

编程入门 行业动态 更新时间:2024-10-24 23:19:06
你如何在IOS中创建SVG路径的动画?(How do you animate an SVG path in IOS?)

我有一个像这样的SVG路径:

<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" version="1.1" baseProfile="full"> <path d="M47.16,66.38c0.62,1.65-0.03,2.93-0.92,4.28c-5.17,7.8-8.02,11.38-14.99,18.84c-2.11,2.25-1.5,4.18,2,3.75c7.35-0.91,28.19-5.83,40.16-7.95" style="fill:none;stroke:black;stroke-width:2" /> </svg>

我可以渲染路径,但似乎无法找到使路径生成动画的方式,因此它看起来就像用铅笔“画画”一样。 animate节点适用于单个坐标系,但不适用于路径。

我最终最终会在iPhone应用程序中使用此动画,无论是使用解析器还是使用UIWebView。

I have an SVG path like this:

<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" version="1.1" baseProfile="full"> <path d="M47.16,66.38c0.62,1.65-0.03,2.93-0.92,4.28c-5.17,7.8-8.02,11.38-14.99,18.84c-2.11,2.25-1.5,4.18,2,3.75c7.35-0.91,28.19-5.83,40.16-7.95" style="fill:none;stroke:black;stroke-width:2" /> </svg>

I can render the path but can't seem to find a way to make the path animate so that it looks like it is "being draw" as if with pencil. The animate node works for single coords but not for paths.

I will eventually end up using this animation in an iPhone app either with a parser or with a UIWebView.

最满意答案

尝试设置'stroke-dashoffset'的动画效果 (请注意,您需要使用匹配的'stroke-dasharray' ),请参阅此示例 。 需要计算以便能够成功使用它的路径的长度可以通过如下脚本获取:

var pathlength = yourPathElm.getTotalLength()

查看示例中的源代码以了解它是如何完成的。

Try animating the 'stroke-dashoffset' (note that you need a matching 'stroke-dasharray' with it), see this example. The length of the path that needs to be computed to be able to use this successfully can be fetched via script like:

var pathlength = yourPathElm.getTotalLength()

View source on the example to see how it's done.

更多推荐

本文发布于:2023-07-05 09:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1035512.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   动画   如何在   IOS   path

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!