简体   繁体   English

如何在圆形轨迹上移动 uiview?

[英]How to move uiview on circle trajectory?

Is there any way to animate uiview moving with cicle trajectory?有没有什么办法可以让 uiview 以 cicle 轨迹移动?在此处输入图像描述

You will have to create a circular path and animate your view on the path.您将必须创建一个圆形路径并在该路径上为您的视图设置动画。 You can use UIBezierPath to create a circular path.您可以使用 UIBezierPath 创建圆形路径。 Here is an example that does what exactly you want.是一个完全符合您要求的示例。

There are a couple of options.有几个选项。 Probably the simplest is to place your view on a parent view, and then animate rotating the parent view around its Z axis.可能最简单的方法是将您的视图放在父视图上,然后围绕其 Z 轴设置旋转父视图的动画。

I guess you could also build a transform that shifts your view, then rotates it, and animate the transform to different rotation values.我猜你也可以构建一个变换来移动你的视图,然后旋转它,并将变换动画化为不同的旋转值。 I'd have to tinker with that.我不得不修补它。 I know the first approach would be quick and easy to set up.我知道第一种方法设置起来既快捷又容易。

As the other poster said, you could also create a keyframe animation that uses a CGPath to animate your view along a curve that approximated the shape of a circle, but that would be much more work.正如另一位发帖人所说,您还可以创建一个关键帧 animation,它使用 CGPath 沿着近似圆形的曲线为您的视图设置动画,但这需要更多的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM