如何在不使用动画的情况下更新SwiftUI列表 [英] How update a SwiftUI List without animation

查看:73
本文介绍了如何在不使用动画的情况下更新SwiftUI列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新一个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列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆