简体   繁体   English

UIView animateWithDuration线性吗?

[英]UIVIew animateWithDuration linear?

I want to animate my multiple UIImageViews to move from point A to point B linearly. 我想为多个UIImageViews设置动画,以从A点线性移动到B点。

i'm using options:UIViewAnimationOptionCurveLinear - Apple docs says: " A linear animation curve causes an animation to occur evenly over its duration. ". 我正在使用options:UIViewAnimationOptionCurveLinear -Apple文档说:“ 线性动画曲线会导致动画在其持续时间内均匀地发生。

Here's the code that i'm using: 这是我正在使用的代码:

[UIView animateWithDuration:1.5
                              delay:0.0
                            options:UIViewAnimationOptionCurveLinear
                         animations:^{

                             //start animation of random grasses with const speed and const y
                             for (int i=0;i<45;i++){
                                 if ([self.view viewWithTag:i+100]){

                                     CGRect frameOfGrass = [self.view viewWithTag:i+100].frame;
                                     frameOfGrass.origin.y = -100;
                                     [self.view viewWithTag:i+100].frame = frameOfGrass;
                                 }}
        }
                         completion:^(BOOL finished){
                           //
  }];

NOTE : Y position of every imageView is random number from 600-700. 注意 :每个imageView的Y位置都是600-700之间的随机数。

But the result looks more like UIViewAnimationOptionCurveEaseOut - "An ease-out curve causes the animation to begin quickly, and then slow as it completes." 但是结果看起来更像UIViewAnimationOptionCurveEaseOut- “缓和曲线使动画快速开始,然后在完成时变慢。” Because all the images slows down at the and. 因为所有图像在和时都会变慢。

Here's screenshots of app running: 这是应用程序运行的屏幕截图:

在此处输入图片说明在此处输入图片说明在此处输入图片说明在此处输入图片说明

Any idea why this is happening? 知道为什么会这样吗?

The travel distance is not the same for all the grass images. 对于所有草图像,行进距离都不相同。 Remember v=d/t. 记住v = d / t。 In your case, all the grass images will travel at different speeds because they need to reach y.origin = -100 at the same time. 在您的情况下,所有草图像将以不同的速度传播,因为它们需要同时达到y.origin = -100。

Try this: 尝试这个:

frameOfGrass.origin.y = frameOfGrass.origin.y - 600;

This should make all the grass images travel the same distance over the same time. 这应该使所有草图像在相同的时间内传播相同的距离。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM