繁体   English   中英

ScrollView 中的 Animation 缺少 SwiftUI 中的最后一个 object

[英]Animation in ScrollView is missing the last object in SwiftUI

我正在尝试创建一个对象列表,当填充每个 object 时,将有一个 animation ,其延迟取决于数组中的 position 。

为了复制我的问题,这里是代码:

struct ScrollViewTest: View{
    
    @State private var indexes = [Int]()
        
    var body: some View{
        VStack{
            ForEach(indexes, id:\.self){ index in
                Text("Index: \(index)")
                    .transition(.opacity)
            }
            
        }
        .onAppear {

            for index in 0..<9{
                withAnimation(Animation.easeInOut.delay(Double(index) * 0.5)){
                    indexes.insert(index, at: index)
                }
            }
        }
    }
}

如您所见, Index 8在 animation 启动之前就已经可见。 我该如何解决这种问题?

我在 Swift 5、Xcode 版本 12.3 上没有看到问题。

显然,此问题仅发生在实时预览中。 我的错误是我确定存在问题,因为我使用实时预览来检查 animation。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM