ios - UIVIew animateWithDuration 线性?

标签 ios iphone objective-c animation uiview

我想为我的多个 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 - “缓出曲线导致动画快速开始,然后在完成时变慢。”因为所有图像在 和 处都变慢了。

这是应用程序运行的屏幕截图:

enter image description here enter image description here enter image description here enter image description here

知道为什么会这样吗?

最佳答案

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

试试这个:

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

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

关于ios - UIVIew animateWithDuration 线性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19546903/

相关文章:

objective-c - 解析带有特殊字符的 XML 文件

ios - 返回上一个 WatchKit 接口(interface) Controller

iphone - iPhone 应用程序上的 Facebook 登录

ios - 如何在 Swift 中从 JSON 数组中删除项目(使用 SwiftyJSON)

ios - Web 服务如何工作?

iphone - 协议(protocol)和委托(delegate)不能正常工作

ios - 如果在数组中找不到值,则从字典中删除对象

ios - RNCryptor:更改哪些设置以提高性能?

iphone - 使用 CLGeocoder 重复地理编码后出现 kCLErrorDomain 错误 2

ios - C 风格二维数组作为 ivar