问题描述
我想更新一个SwiftUI列表而没有任何插入动画.我的 List
是从 @EnvironmentObject
获取数据的我已经尝试过将 List
本身和 PassthroughSubject.send()
包装在 withAnimation(.empty)
块中,但这无济于事.
I want to update a SwiftUI List without any insert animation.My List
is getting its data from an @EnvironmentObject
I already tried to wrap the List
itself and the PassthroughSubject.send()
in a withAnimation(.empty)
block but this does not help.
一个非常非常肮脏的解决方法是调用 UIView.setAnimationsEnabled(false)
(是的,UIKit对SwiftUI产生了影响),但是必须有一种类似于SwiftUI的方式来设置自定义插入动画./p>
A very very dirty workaround is to call UIView.setAnimationsEnabled(false)
(yes, UIKit has impact on SwiftUI), but there must be a SwiftUI-like way to set custom insert animations.
推荐答案
此方法有效,只需将 .id(UUID())
放在列表末尾
This works, just place .id(UUID())
at the end of your list
List {
// for each etc
}.id(UUID())
UIKit的类似reloadData的排序
Sort of like reloadData for UIKit
这篇关于如何在不使用动画的情况下更新SwiftUI列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!