【问题标题】:iOS - Animate movement of an image without effectsiOS - 没有效果的图像动画移动
【发布时间】:2014-03-04 03:29:50
【问题描述】:

我想在没有效果的情况下为图像的移动设置动画。要正常为其设置动画,我可以使用:

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

    [self.image setFrame:currentFrame];

}];

然而,我发现如果使用这种方法,图像会逐渐加速,快一点,然后逐渐停止。

有什么方法可以为 UIImageView 的移动设置动画,让视图始终保持相同的速度?

【问题讨论】:

    标签: objective-c uiimageview


    【解决方案1】:

    您的动画会加速和减速,因为它使用“自然”UIViewAnimationOptionCurveEaseInOut 曲线。使用UIViewAnimationOptionCurveLinear 选项来使用恒速运动:

    [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){
        }
    ];
    

    【讨论】:

      【解决方案2】:
      [UIView animateWithDuration:1.0 delay:0.0 options:0 animations:^{
      
      } completion:^(BOOL finished) {
      
      }];
      

      【讨论】:

      • 尽量避免只使用代码的答案...即使这是正确的,但看到它的人不会知道代码的作用。
      猜你喜欢
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      相关资源
      最近更新 更多