添加TabView会使导航栏无法覆盖SwiftUI中的安全区域 [英] Adding a TabView makes the Navigation Bar not cover the safe area in SwiftUI

查看:80
本文介绍了添加TabView会使导航栏无法覆盖SwiftUI中的安全区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SwiftUI iOS应用中添加TabView时,导航栏将停止覆盖该缺口

When adding a TabView in my SwiftUI iOS App, the Navigation Bar stops covering up the notch

我尝试为TabView实现创建另一个文件(修改SceneDeletage等)

I've tried creating another file for the TabView implementation ( Modifying SceneDeletage and so on)

这是一个不带TabView的简单代码,它使导航栏覆盖了安全区域(又称缺口)

Here is a simple code without TabView that makes the Navigation Bar cover the safe area (aka the notch)

import SwiftUI

struct ContentView: View {
    var body: some View {

        NavigationView{
            ScrollView{
                HStack{
                    VStack{
                        ForEach((1...10), id: \.self){_ in
                            Text("Hello")
                            .padding(.leading, 20)
                        }
                    }
                    Spacer()
                    //.padding(.leading, 20)
                }
            }
        .navigationBarTitle("Title Covers Safe Area")
        }

    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

这是TabView的代码,它使导航栏不会掩盖安全区域

Here is a code with TabView that makes the Navigation Bar NOT cover up the safe area

import SwiftUI

struct ContentView: View {
    var body: some View {

        TabView {
            NavigationView{
                ScrollView{
                    HStack{
                        VStack{
                            ForEach((1...10), id: \.self){_ in
                                Text("Hello")
                            }
                        }
                        Spacer()
                    }
                    .padding(.leading, 20)
                }
                .navigationBarTitle("Doesn't Cover Safe Area")
            }
                .tabItem {
                    Image(systemName: "1.circle")
                    Text("First")
                }.tag(0)
            HStack{
                Spacer()
                VStack{

                    Spacer()
                    Text("Second View")
                        .font(.system(size: 40))
                }

            }

                .tabItem {
                    Image(systemName: "2.circle")
                    Text("Second")
                }.tag(1)
        }

    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

推荐答案

您可以使用方法 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆