小编ykl*_*lcs的帖子

iOS 15 SwiftUI TabView 选项卡栏外观不会在视图之间更新

iOS 15TabView根据加载视图的滚动位置设置 的外观。但是,这似乎不会在选项卡栏中切换的视图之间更新。我该如何解决这个问题以便外观正确更新?

  1. 打开不滚动内容的选项卡式视图(“无滚动视图”)使用选项卡栏的透明背景。

  2. 导航到具有滚动内容的选项卡式视图(“滚动视图”)后,将使用半透明背景。

  3. 然而,当回到“无滚动视图”时,半透明背景仍然保留,而不是被透明背景替换。

我确实注意到,当我打开控制中心或应用程序切换器并返回时,外观会正确更新。

无滚动视图透明 滚动视图半透明 无滚动视图半透明

再生产:

enum Tab {
    case scroll
    case noScroll
}

struct ContentView: View {
    @State var selection: Tab = .noScroll
    
    var body: some View {
        TabView(selection: $selection) {     
            Text("Should have a transparent tab bar")
                .tabItem{ Label("No-scroll", systemImage: "xmark.circle") }
                .tag(Tab.noScroll)
            
            ScrollView {
                VStack(spacing: 10) {
                    ForEach(0..<100) {_ in
                        Text("Should have a translucent tab bar")
                    }
                }
            }
            .tabItem { Label("Scroll", systemImage: "circle") }
            .tag(Tab.scroll)
        }
    }
}

Run Code Online (Sandbox Code Playgroud)

ios swift swiftui

13
推荐指数
3
解决办法
8030
查看次数

标签 统计

ios ×1

swift ×1

swiftui ×1