以圆周运动的方式围绕点移动对象

时间:2012-12-02 08:23:37

标签: ios objective-c animation

我在视图中有一些对象,我想在屏幕上移动它们自己的点。我希望它们看起来几乎是静止的,但是有一个轻微的圆周运动(不是旋转,物品将保持笔直和水平),有点像浮标在海洋中上下浮动,也有一些水平运动。

我的基本想法是在对象周围移动锚点。我只想要一个微妙的效果,物体不会在整个屏幕上移动。最多10-20分。他们将是UIButtons仍然能够被按下。到目前为止,我搜索过的所有内容都是围绕一个点旋转的结果,而不是我所追求的结果。

1 个答案:

答案 0 :(得分:1)

您可以使用CAKeyframeAnimation使您的对象遵循一个小圆圈或任何其他适合您需求的路径。以下是创建和使用CAKeyframeAnimation对象的方法。

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
CGMutablePathRef * circle = CGPathCreateWithEllipseInRect(CGRectMake(/* the center of your object and the radius of your circle*/));
pathAnimation.path = circle;
CGPathRelease(circle);
[buttonView.layer addAnimation:pathAnimation forKey:@"animatePath"];

这应该让你开始。请注意,您需要导入QuartzCore框架才能使其正常工作。

相关问题