UIView动画的路径不是线性的

chi*_*s54 1 animation uiimageview ios

可能重复:
如何沿曲线路径设置视图或图像的移动动画?

我有一个iOS应用程序,我想动画落叶(或几个).我有我的叶子图像,ImageView我从文档中找到了一个简单的动画:

[UIView animateWithDuration:4.0f
                          delay:0
                          options:UIViewAnimationTransitionFlipFromLeft
                          animations:^(void)
                          {
                              leaf1ImageView.frame = CGRectMake(320, 480, leaf1ImageView.frame.size.width,leaf1ImageView.frame.size.height);
                          }
                          completion:NULL];
Run Code Online (Sandbox Code Playgroud)

这将使叶片从其起始位置直线进入右下角.我如何设置动画来跟随路径或曲线如抛物线或正弦曲线,甚至可能旋转图像或视图?这会在动画块中完成吗?提前致谢!

Fel*_*lix 10

您可以使用CAKeyframeAnimationCGPath执行此操作.代码看起来像这样:

CAKeyframeAnimation *leafAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
leafAnimation.duration = 10.0;
leafAnimation.path = /* your CGPathRef */;
[leaf1ImageView.layer addAnimation:leafAnimation forKey:@"leafAnimation"];
Run Code Online (Sandbox Code Playgroud)