Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

ios - 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.

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...