簡體   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