为什么 SwiftUI 中的 VStack 之间存在间隙?

Why is there a Gap between VStacks in SwiftUI?

在用红线绘制的区域中可以看到白色。如果我改变最具包容性的 Vstack 的背景颜色,那个白色区域就会改变。

删除 spacer() 行无效。

为什么中间没有space却有空隙?

struct TabbarView: View {    
var body: some View {        
    VStack{
        Spacer()   
            ZStack{
                Color.orange.opacity(0.5)
                VStack(spacing: 0){
                    Text("Home")
                        .padding()
                }
            }            
        Spacer()            
        HStack{
            VStack{
                Image(systemName: "homekit")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: UIScreen.main.bounds.size.width / 15, height: UIScreen.main.bounds.size.height / 25)
            }
        }
        .frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height / 13)
        .background(Color.purple)            
    }
    .ignoresSafeArea()      
   // .background(Color.purple.shadow(radius: 2))
}

}

enter image description here

您可以为 VStack 添加:

 VStack {}
            .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)

更新:

struct ContentView: View {
    var body: some View {
        ZStack {
            Color.orange.opacity(0.5)
            VStack {
                Spacer()
                VStack(spacing: 0){
                    Text("Home")
                        .padding()
                }
                Spacer()
                HStack {
                    VStack {
                        Image(systemName: "homekit")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 25, height: 25, alignment: .center)
                            .frame(width: UIScreen.main.bounds.size.width / 15, height: UIScreen.main.bounds.size.height / 25)
                    }
                }
                .frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height / 13)
                .background(Color.purple)
            }
            
        }
        .ignoresSafeArea()
        .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
    }
}

你错误地使用了嵌套,标签有一个原生的 TabView

结果: