swift - 有没有一种方法可以在每次 for 循环重复时返回一些东西而无需退出 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 个语句之一。谢谢您的帮助!
解决方案
您可以使用 forEach:
UIView.animate(
withDuration: TimeInterval(vectorToFinalPointLength / 1800),
delay: 0,
options: .curveEaseOut,
animations: {
self.ClosetItems.enumerated().forEach { i, item in
item.center.x = finalPointCloset[i]
}
}
)
推荐阅读
- mongodb - 更新 mongo/mongoose 版本后更新文档时出错
- excel - 当您在子程序内部时,事件可以触发吗?
- javascript - 使用 jQuery 单击后更改按钮的文本
- antlr - 确定匹配哪个令牌
- ssh - Vagrant Virtualbox端口转发:对等方重置连接
- android - 更新小部件时出现空列表异常
- c# - 在 ListView 控件中显示年度总计
- javascript - 您是否应该在构造函数中定义组件状态的所有属性?
- android - 盲人/视力障碍用户的最佳时间选择器
- ruby-on-rails - 将构建过程依赖于与另一个容器的通信的应用程序 Docker 化