有没有一种方法可以在每次for循环重复时返回某些内容,而不会在Swift中退出循环?

时间:2020-02-26 04:24:12

标签: swift

我希望在平移一个图像后让很多图像具有动量,要使其变得最简单,我将使用某种for循环来给UIView.animate图像的动画数据,但是如果返回要使其中一个图像工作的for循环的数据结束。我唯一的另一个想法是要有一个数组来存储这些值并返回它,但是我不知道该存储什么变量。抱歉,我是Swift的新手,老实说,我不知道其中有什么叫什么,但是希望通过代码您可以理解我的工作。

UIView.animate(withDuration: TimeInterval(vectorToFinalPointLength/1800) ,delay: 0, options: .curveEaseOut, animations: {
            for (i,item) in self.ClosetItems.enumerated() {
                return item.center.x = finalPointCloset[i]
            }
        })

动画:需要多个语句,但是由于返回结束了整个for循环,因此它仅获得数组中30个之一。 感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以使用forEach:

UIView.animate(
    withDuration: TimeInterval(vectorToFinalPointLength / 1800),
    delay: 0, 
    options: .curveEaseOut,
    animations: {
        self.ClosetItems.enumerated().forEach { i, item in
            item.center.x = finalPointCloset[i]
        }
    }
)
相关问题