沿路径放置对象,然后移动它(包含IMG)

编程入门 行业动态 更新时间:2024-10-26 23:27:30
本文介绍了沿路径放置对象,然后移动它(包含IMG)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个问题(;)),需要您的帮助.

I have a problem ( ;) ) and I need your help.

让我们看一下图像:

1)我有一条路.可以这样说:

1) I have a path. Lets say it's like this:

let bezierPath = UIBezierPath() bezierPath.moveToPoint(CGPointMake(10.5, 47.5)) bezierPath.addCurveToPoint(CGPointMake(45.5, 23.5), controlPoint1: CGPointMake(10.5, 47.5), controlPoint2: CGPointMake(32.5, 23.5)) bezierPath.addCurveToPoint(CGPointMake(84.5, 47.5), controlPoint1: CGPointMake(58.5, 23.5), controlPoint2: CGPointMake(84.5, 47.5)) bezierPath.addLineToPoint(CGPointMake(10.5, 47.5)) bezierPath.closePath() UIColor.redColor().setStroke() bezierPath.lineWidth = 1 bezierPath.stroke()

2)我有一个UIImageView.第一个问题是:如何将其放在路径的指定部分(A点)的顶部?

2) I have an UIImageView. First question is: How to put it on the top of specified part of the path (A point) ?

3)第二个问题:如何从A点到B点对其进行动画处理?

3) Second question: How to animate it from point A to B ?

推荐答案

使用CAKeyframeAnimation,您可以使用制作的路径创建动画

By using CAKeyframeAnimation, you can create an animation using the path you made

let animation = CAKeyframeAnimation() // Could also be position.x or position.y if you want to animate a separate axis. animation.keyPath = "position" animation.repeatCount = 0 // How many times to repeat the animation animation.duration = 5.0 // Duration of a single repetition animation.path = bezierPath.CGPath

然后将其附加到图像的图层上

and then attach it to your image's layer

imageView.layer.addAnimation(animation, forKey: "move image along bezier path")

这另一个 stackoverflow问题帮助我形成了这个答案,如果有的话否则,您可以始终参考 docs .

This other stackoverflow question helped me form this answer, and if all else fails, you could always refer to the docs.

更多推荐

沿路径放置对象,然后移动它(包含IMG)

本文发布于:2023-10-29 20:29:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540665.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:沿路   对象   IMG

发布评论

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

>www.elefans.com

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