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

查看:28
本文介绍了沿圆形路径的 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天全站免登陆