【问题标题】:UIVIew animateWithDuration linear?UIVIew animateWithDuration 线性?
【发布时间】:2013-10-24 00:33:03
【问题描述】:

我想为我的多个 UIImageView 设置动画,使其从 A 点线性移动到 B 点。

我正在使用 options:UIViewAnimationOptionCurveLinear - Apple 文档说:“线性动画曲线会导致动画在其持续时间内均匀发生。”。

这是我正在使用的代码:

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

注意: 每个 imageView 的 Y 位置是 600-700 的随机数。

但结果看起来更像 UIViewAnimationOptionCurveEaseOut - “缓出曲线导致动画开始快速,然后在完成时变慢。”因为所有图像在 and 处都会变慢。

这是应用运行的截图:

知道为什么会这样吗?

【问题讨论】:

    标签: ios iphone objective-c animation uiview


    【解决方案1】:

    所有草图像的行进距离都不相同。记住 v=d/t。在您的情况下,所有草图像将以不同的速度行进,因为它们需要同时达到 y.origin = -100。

    试试这个:

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

    这应该使所有草图像在同一时间行进相同的距离。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-07
      • 2013-11-24
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 2014-04-30
      • 2013-08-08
      相关资源
      最近更新 更多