gpt4 book ai didi

arrays - Swift:放置整个数组的最有效方法?

转载 作者:可可西里 更新时间:2023-11-01 02:04:02 24 4
gpt4 key购买 nike

我正在放置数组 graphics 中的所有 4 个项目,然后移动其中三个。

除了 for 循环,有没有更短的方法将整个数组 graphics 放在同一位置?即如何将整个阵列放在一个点上?

// Position a graphic in each quadrant.
for i in 0 ... 3 {
scene.place(graphics[i], at: Point(x: x, y: y))
}
graphics[1].move(to: Point(x: x, y: -y), duration: 2)
graphics[2].move(to: Point(x: -x, y: -y), duration: 2)
graphics[3].move(to: Point(x: -x, y: y), duration: 2)

最佳答案

尝试使用 graphics.forEach{ scene.place($0, at: Point(x: x, y: y)) }

关于arrays - Swift:放置整个数组的最有效方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44576437/

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