You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI中LazyVGrid内一个ForEach为何会覆盖另一个循环?

异常表现与测试代码
  • 异常表现1:网格实际仅渲染出1个黑色矩形和10个红色矩形(预期应为5个黑色矩形+10个红色矩形)
  • 异常表现2:网格实际仅渲染出5个黑色矩形和6个红色矩形(预期应为5个黑色矩形+10个红色矩形)

测试用最简代码:

LazyVGrid(columns: Array(repeating: .init(.flexible(), alignment: .bottom), count: 7), spacing: 12) {
    ForEach(0..<5, id: \.self) { _ in
        Rectangle()
            .fill(.black)
    }

    ForEach(0..<10, id: \.self) { _ in
        Rectangle()
            .fill(.red)
    }
}

内容的提问来源于stack exchange,提问作者Mark Daylight

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 01:09:50