简体   繁体   English

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

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

I'm trying to create a list of objects that when filled every object will have an animation with a delay depending on its position in the array.我正在尝试创建一个对象列表,当填充每个 object 时,将有一个 animation ,其延迟取决于数组中的 position 。

To replicate my problem here's the code:为了复制我的问题,这里是代码:

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)
                }
            }
        }
    }
}

As you can see, Index 8 is already visible before the animation even started.如您所见, Index 8在 animation 启动之前就已经可见。 How do I solve this kind of problem?我该如何解决这种问题?

I am not seeing an issue on Swift 5, Xcode version 12.3.我在 Swift 5、Xcode 版本 12.3 上没有看到问题。

Apparently, this problem occurs only on the live preview.显然,此问题仅发生在实时预览中。 My mistake was that I determined that there is a problem because I used the live preview to examine the animation.我的错误是我确定存在问题,因为我使用实时预览来检查 animation。

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

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