【问题标题】:SwiftUI Tabview FixSwiftUI Tabview 修复
【发布时间】:2022-01-20 20:22:00
【问题描述】:

在我的应用程序中,我有一个标签视图。其中 4 个选项卡是空白页。没有清单或任何东西。其中一个有一个列表,并且由于滚动功能而使标签栏半透明。问题是,每当我离开列表页面时,半透明的标签栏都会保留。我不希望它。我希望它恢复透明。如果您查看照片应用程序,它会执行此操作。它很容易从透明变为半透明,然后又变回来。

    var body: some View {
    TabView(selection: $selectedTab) {
                Schedule()
                    .tag(Tab.schedule)
                    .tabItem {
                        Label("Schedule", systemImage: "calendar")
                    }

                Messaging()
                    .tag(Tab.messaging)
                    .tabItem {
                        Label("Messaging", systemImage: "bubble.left")
                    }
                Dashboard()
                    .tag(Tab.home)
                    .tabItem {
                        Label("Dashboard", systemImage: "note")
            }
                Resources()
                    .tag(Tab.resources)
                    .tabItem {
                        Label("Resources", systemImage: "folder")
                    }
                MailViewTest()
                    .tag(Tab.settings)
                    .tabItem {
                        Label("Settings", systemImage: "gear")
            }
    }

Link to video

如果您观看此视频,我会展示它是如何保留的,但当我滚动浏览列表时,它就会消失。

【问题讨论】:

    标签: swift swiftui tabview


    【解决方案1】:

    尝试重置TabView,点赞

    TabView(selection: $selectedTab) {
        // other code
    }
    .id(selectedTab)       // << here !!
    

    【讨论】: