道路不是直线上的UIView动画 [英] UIView animations on a path not linear
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/1142727/how-can-i-animate-the-movement-of-a-view-or-image-along-a-curved-path\">How我可以动画沿曲线路径视图或图像的运动?
我有我要动画落叶(或几个)iOS应用程序。我在的ImageView
我的叶形象,我已经想通了从文档简单的动画:
I have an iOS application that I want to animate a falling leaf (or several). I have my leaf image in an ImageView
and I've figured out a simple animation from the documentation:
[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];
这将使叶片从其起始位置到右下角在一条直线上。我怎么会这个动画跟随象抛物线或正弦曲线路径或曲线,甚至旋转图像或查看?这会在动画块怎么办?提前致谢!
This will make the leaf go from its starting position to the bottom right corner in a straight line. How would I animate this to follow a path or curve like a parabola or sinusoid and maybe even rotate the image or view? Would this be done in the animations block? Thanks in advance!
推荐答案
您可以使用<一个做到这一点href=\"https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CAKeyframeAnimation_class/Introduction/Introduction.html\">CAKeyframeAnimation和<一个href=\"http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGPath/Reference/reference.html\">CGPath.在code看起来是这样的:
You can do this with a CAKeyframeAnimation and a CGPath. The code looks something like this:
CAKeyframeAnimation *leafAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
leafAnimation.duration = 10.0;
leafAnimation.path = /* your CGPathRef */;
[leaf1ImageView.layer addAnimation:leafAnimation forKey:@"leafAnimation"];
这篇关于道路不是直线上的UIView动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!