iOS:移动 UIImageView
在我的应用程序中,我想在 .png 中移动一些 UIImageView;这是一只小昆虫,我想模拟他的飞行。例如,我希望这个 png 在将倒八移动为无限符号 ∞ 时执行此操作
In my app I want to move a little UIImageView with inside a .png; this is a little insect and I want to simulate his flight. At example I want that this png do when it move an inverted eight as the infinite simbol ∞
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 CoreAnimation。您可以对视图进行子类化,为昆虫创建子视图,然后按照定义的路径为其分配动画。
你的 UIImageView 可以是动画的。如果是苍蝇,您可以为翅膀移动做一些帧:
然后为昆虫设置一个初始帧:
然后定义路径:
我将如何执行无限循环路径留给您:)
希望它有所帮助!
You may use CoreAnimation. You can subclass a view, create a subview for the insect, and then assign an animation to it, following a defined path.
Your UIImageView could be animated. If it's a fly, you can do a few frames for wing moves:
Then set an init frame for the insect:
And then define the path:
I leave how to do the infinite loop path up to you :)
Hope it helps!
通常,如果您要移动物体,我建议使用 [UIView animate...]。然而,您希望某些东西在复杂、弯曲的路径上移动。因此,我建议提出一个方程,给出昆虫的 (x,y) 作为时间的函数,然后以相当小的时间间隔启动 NSTimer,每次获得更新时,移动昆虫(也许使用 [UIView animate...])。
另一种方法是使用二维动画框架,例如 cocos2d - 然后,您可以获得与帧刷新率相关联的“更新”调用,在其中使用与以下相同的方程更新昆虫的位置多于。
Normally, if you were to be moving things around, I'd suggest using [UIView animate...]. However, you want something to move on a complex, curvy path. So instead, I'd suggest coming up with an equation that gives the (x,y) for the insect as a function of time, and then start an NSTimer with a fairly small time interval, and every time you get an update, move the insect (perhaps using [UIView animate...]).
Another way to go is to use a 2-d animation framework such as cocos2d - then, you can get an 'update' call linked to the frame refresh rate, inside of which you update the position of your insect using the same equation as from above.