dav*_*vid 4 iphone core-animation uiview uiimageview
我需要让我的小家伙(在UIIamgeView中)向前跳,它必须看起来很自然.我想知道有没有办法用CoreAnimation(beginAnimation/commitAnimation)做到这一点?
我可以通过在空中设置一个点来做到这一点,但运动看起来不自然:P
小智 14
阅读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"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7414 次 |
| 最近记录: |