这个问题在这里已经有了答案:
9年前关闭。
Possible Duplicate:
How can I animate the movement of a view or image along a curved path?
我有一个 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];
这将使叶子从其起始位置直线移动到右下角。我将如何对其进行动画处理以遵循抛物线或正弦曲线等路径或曲线,甚至可能旋转图像或 View ?这会在动画 block 中完成吗?提前致谢!
最佳答案
您可以使用 CAKeyframeAnimation和 CGPath .代码看起来像这样:
CAKeyframeAnimation *leafAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
leafAnimation.duration = 10.0;
leafAnimation.path = /* your CGPathRef */;
[leaf1ImageView.layer addAnimation:leafAnimation forKey:@"leafAnimation"];
关于ios - 非线性路径上的 UIView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12231600/