[英]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.