Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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. How do I solve this kind of problem?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

I am not seeing an issue on Swift 5, Xcode version 12.3.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...