gpt4 book ai didi

ios - UIVIew animateWithDuration 线性?

转载 作者:行者123 更新时间:2023-11-29 13:02:00 28 4
gpt4 key购买 nike

我想为我的多个 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com