Animation slows down as it ends

1.3k views Asked by At

I have a translate animation, moving my button from A to B.

That route looks like this:

1) Button slowly accelerates 2) At the middle of animation gets to the peak of it's speed 3) Slows down as it approaches the end

This is my code

[UIView animateWithDuration:speed
                      delay:delay
                    options:UIViewAnimationOptionAllowUserInteraction
                 animations:^(void){
                     [UIView setAnimationRepeatCount:5];
                     cloud.frame = (CGRectMake(cloud.frame.origin.x,   
cloud.frame.origin.y+900, cloud.frame.size.width, cloud.frame.size.height));

                 }completion:nil];

I want my animation to have a same speed all the time.

How can I achieve this?

2

There are 2 answers

0
Adis On BEST ANSWER

Add the UIViewAnimationOptionCurveLinear to your animation options, like this:

[UIView animateWithDuration:speed
                      delay:delay
                    options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveLinear
                 animations:^(void){
                     [UIView setAnimationRepeatCount:5];
                     cloud.frame = (CGRectMake(cloud.frame.origin.x,   
cloud.frame.origin.y+900, cloud.frame.size.width, cloud.frame.size.height));

                 }completion:nil];
0
Feras Arabiat On

I think you wanna try setting the "option" parameter to:

UIViewAnimationOptionCurveLinear