문제

I would like to animate the movement of an image without effects. To animate it normally, I could use:

[UIView animateWithDuration:2.5f animations:^{
    CGRect currentFrame=self.image.frame;
    currentFrame.origin.x-=10;

    [self.image setFrame:currentFrame];

}];

Yet, I found that if this method is used, the image gradually speeds up, goes a little faster, then gradually comes to a stop.

Is there any way to animate the movement of a UIImageView, keeping the view at the same speed the entire time?

도움이 되었습니까?

해결책

Your animation speeds up and slows down because it uses the "natural" UIViewAnimationOptionCurveEaseInOut curve. Use UIViewAnimationOptionCurveLinear option to use constant speed motion:

[UIView animateWithDuration:2.5f
    delay:0
    options:UIViewAnimationOptionCurveLinear
    animations:^{
        CGRect currentFrame=self.image.frame;
        currentFrame.origin.x-=10;
        [self.image setFrame:currentFrame];
    } 
    completion:^(BOOL finished){
    }
];

다른 팁

[UIView animateWithDuration:1.0 delay:0.0 options:0 animations:^{

} completion:^(BOOL finished) {

}];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top