gpt4 book ai didi

ios - SwiftUI - 如何避免在修改来自同一结构的状态变量时刷新列表

转载 作者:行者123 更新时间:2023-12-01 19:35:52 24 4
gpt4 key购买 nike

我有一个主 View ,其中包含一个带有 TabView 的主体,每个选项卡显示一个不同的列表。此外,我在主类的顶部声明了一个状态变量,仅用于控制是否必须显示类似模态的 View 。

问题是,当我更改该状态变量的值时,主 View 的所有主体都用动画重绘。这不是理想的行为,因为我没有更改与更新该 var 的列表关联的数据。

struct HomeView: View {
@State private var selection = 0
@State var modalShown = false //This is the problematic var that makes a list to be updated with an animation

@EnvironmentObject var filters: UserFilters
@EnvironmentObject var filtersViewController: FiltersViewController

init() {
UITabBar.appearance().backgroundColor = #colorLiteral(red: 0.03921568627, green: 0.03921568627, blue: 0.03921568627, alpha: 1)
UITabBar.appearance().barTintColor = #colorLiteral(red: 0.03921568627, green: 0.03921568627, blue: 0.03921568627, alpha: 1)
}

var body: some View {
return ZStack {
TabView(selection: $selection){
IncidencesView(modalShown: $modalShown) //A view that contains a list that is being refreshing

至少,有没有办法避免列表更新动画?

谢谢!

最佳答案

At least, is there a way to avoid the list updating animation?



提供的代码快照不可测试,所以只是即时......尝试以下
IncidencesView(modalShown: $modalShown.animation(nil))

关于ios - SwiftUI - 如何避免在修改来自同一结构的状态变量时刷新列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60167546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com