简体   繁体   English

SwiftUI 透明 TabView(没有背景模糊)?

[英]SwiftUI transparent TabView (without background blur)?

From what I found on the inte.net, the Tabview in this version of Swift is meant to be transparent.根据我在 inte.net 上的发现,这个版本的 Swift 中的 Tabview 是透明的。

But in my case it always dispalys a grayish tone with a line on top when there is something underneath it in the view it is displaying.但在我的例子中,当它显示的视图中有东西在它下面时,它总是显示灰色调,顶部有一条线。 If I scroll down to a space in that view which is empty, the tabview becomes transparent again.如果我向下滚动到该视图中的空白处,则 tabview 再次变为透明。

I have been trying to find a solution to this for ages but I'm a absolute noob.多年来我一直在努力寻找解决方案,但我绝对是菜鸟。 Can someone please help me fix this and make it always transparent?有人可以帮我解决这个问题并让它始终透明吗? Thank you so much!太感谢了!

Screenshots:截图:

Grayish when there's something underneath当下面有东西时呈灰色

Transparent when there's nothing underneath下面什么都没有时是透明的

Use UIBarAppearance.configureWithTransparentBackground() .使用UIBarAppearance.configureWithTransparentBackground()

struct ContentView: View {
    
    init() {
        let transparentAppearence = UITabBarAppearance()
        transparentAppearence.configureWithTransparentBackground() // 🔑   
        UITabBar.appearance().standardAppearance = transparentAppearence
    }
    
    var body: some View {
        TabView {
            List {
                ForEach(1...40, id: \.self) { eachRowIndex in
                    Text("Row \(eachRowIndex)")
                }
            }
            .listStyle(.plain)
            .tabItem {
                Image(systemName: "house.fill")
                Text("Home")
            }
        }
    }
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM