我想为我的多个 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 - “缓出曲线导致动画快速开始,然后在完成时变慢。”因为所有图像在 和 处都变慢了。
这是应用程序运行的屏幕截图:
知道为什么会这样吗?
最佳答案
所有草图像的行进距离都不相同。记住 v=d/t。在您的情况下,所有草图像将以不同的速度行进,因为它们需要同时达到 y.origin = -100。
试试这个:
frameOfGrass.origin.y = frameOfGrass.origin.y - 600;
这应该使所有草图像在同一时间移动相同的距离。
关于ios - UIVIew animateWithDuration 线性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19546903/