简体   繁体   中英

UIVIew animateWithDuration linear?

I want to animate my multiple UIImageViews to move from point A to point B linearly.

i'm using options:UIViewAnimationOptionCurveLinear - Apple docs says: " A linear animation curve causes an animation to occur evenly over its duration. ".

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.

But the result looks more like UIViewAnimationOptionCurveEaseOut - "An ease-out curve causes the animation to begin quickly, and then slow as it completes." 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. In your case, all the grass images will travel at different speeds because they need to reach y.origin = -100 at the same time.

Try this:

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

This should make all the grass images travel the same distance over the same time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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