沿着圆形路径的UIView动画? [英] UIView animation along a round path?

查看:268
本文介绍了沿着圆形路径的UIView动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让我的小家伙(在UIIamgeView中)向前跳,它必须看起来很自然。我想知道有没有办法用CoreAnimation(beginAnimation / commitAnimation)来做?

I need to make my little guy (in a UIIamgeView) jump forward and it has to look natural. I want to know is there a way to do it with CoreAnimation (beginAnimation/commitAnimation)?

我可以通过在空中设置一个点而不是运动来做到这一点看起来不自然:P

I could do it by setting a point in between in the air but the movement looks not natural :P

推荐答案

阅读Brad Larson的帖子,我最终得到了一个很好的功能,让我的图像跟随一个圆圈。

Reading Brad Larson's post, I ended up with a nice function to make my image follow a circle.

您需要导入QuartzCore框架:#import

You need to import QuartzCore framework: #import

以下是代码:

// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = INFINITY;
//pathAnimation.rotationMode = @"auto";
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = 5.0;

// Create a circle path
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGRect circleContainer = CGRectMake(0, 0, 400, 400); // create a circle from this square, it could be the frame of an UIView
CGPathAddEllipseInRect(curvedPath, NULL, circleContainer);

pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);

[self.imageView.layer addAnimation:pathAnimation forKey:@"myCircleAnimation"];

这篇关于沿着圆形路径的UIView动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆