【发布时间】:2010-03-31 18:47:54
【问题描述】:
我需要让我的小家伙(在 UIIamgeView 中)向前跳跃,并且它必须看起来很自然。我想知道有没有办法用 CoreAnimation (beginAnimation/commitAnimation) 做到这一点?
我可以通过在空中设置一个点来做到这一点,但动作看起来不自然:P
【问题讨论】:
标签: iphone uiview core-animation uiimageview
我需要让我的小家伙(在 UIIamgeView 中)向前跳跃,并且它必须看起来很自然。我想知道有没有办法用 CoreAnimation (beginAnimation/commitAnimation) 做到这一点?
我可以通过在空中设置一个点来做到这一点,但动作看起来不自然:P
【问题讨论】:
标签: iphone uiview core-animation uiimageview
阅读了 Brad Larson 的帖子,我最终得到了一个很好的功能,可以让我的图像跟随一个圆圈。
需要导入 QuartzCore 框架:#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"];
【讨论】:
创建一个CAKeyframeAnimation 并将一个CGPath 分配给它的path 属性。
【讨论】:
为了跟进 Ole 的回答,my answer 到 this question 提供了使用 CAKeyframeAnimation 执行此类弯曲动画的代码。
【讨论】: