iPhone 11 Simulator 中的主页视图背景颜色未全屏显示

Home page view background color in not on full screen in iPhone 11 Simulator

我正在尝试在 SwiftUI 中构建应用程序并面临 1 个挑战(Xcode 版本 11.5)-

  1. 运行 应用程序在 iPhone 11 模拟器上时,背景颜色不会出现在整个屏幕上,但屏幕底部仍然是白色的 运行在 iPhone 8 模拟器上,它工作正常。不确定是模拟器问题还是代码问题。我尝试添加 Spacer,更改 VStack,HStack 但没有用。

    struct HomePageView: View {
        @State var size = UIScreen.main.bounds.width / 1.6
    
        var body: some View {
            GeometryReader{geometry in
                VStack {
                    HStack {
                        ZStack{
                            NavigationView{
                                ZStack {
                                    ScrollView(.vertical, showsIndicators: false) {
                                        VStack {
                                            View1()
                                        }.frame( maxWidth: .infinity)
                                    }
    
                                    .navigationBarItems(leading: Button(action: {
                                        self.size = 10
    
                                    }, label: {
                                        Image("menu")
                                            .resizable()
                                            .frame(width: 30, height: 30)
                                    }).foregroundColor(.appHeadingColor), trailing:
                                        Button(action: {
                                            print("profile is pressed")
                                        }) {
                                            HStack {
                                                NavigationLink(destination: ProfileView()) {
                                                    LinearGradient.lairHorizontalDark
                                                        .frame(width: 30, height: 30)
                                                        .mask(
                                                            Image(systemName: "person.crop.circle")
                                                                .resizable()
                                                                .scaledToFit()
                                                    )
                                                }
                                            }
                                        }
                                    ).navigationBarTitle("Home", displayMode: .inline)
                                }
                            }
                            HStack{
                                menu(size: self.$size)
                                    .cornerRadius(20)
                                    .padding(.leading, -self.size)
                                    .offset(x: -self.size)
                                Spacer().background(Color.lairBackgroundGray)
                            }
                            //Spacer()
                        }.animation(.spring()).background(Color.lairBackgroundGray)
                        //Spacer()
                    }.padding(.top, UIApplication.shared.windows.first?.safeAreaInsets.top)
    
                        .padding(.bottom, UIApplication.shared.windows.first?.safeAreaInsets.bottom)
                }.frame(height: geometry.size.height).background(Color.lairBackgroundGray)
            }//.background(Color.lairBackgroundGray.edgesIgnoringSafeArea(.all))
        }
    }
    

    下面是我的另一个视图,它基本上作为主视图的一部分绘制在屏幕上。请原谅我在这里放了这么多代码,但想确定是不是因为 View1 -

    结构视图1:视图{ @State 变量索引 = 0 var body: 一些视图{ // 滚动视图 { GeometryReader { 几何输入 堆栈{ 堆栈{ 堆栈 { Z堆栈{ 圆圈() .trim(从:0,到:1) .stroke(Color.lairDarkGray.opacity(0.09), 风格: StrokeStyle(lineWidth: 34, lineCap: .round)) .frame(宽度: 80, 高度: 80)

                                    Circle()
                                        .trim(from: 0, to: 0.5)
                                        .stroke(LinearGradient(gradient: Gradient(colors: [.buttonGradientStartColor, .buttonGradientEndColor]), startPoint: UnitPoint(x: -0.2, y: 0.5), endPoint: .bottomTrailing), style: StrokeStyle(lineWidth: 34, lineCap: .round))
                                        .frame(width: 80 , height: 80)
                                        .rotationEffect(.init(degrees: -90))
    
                                        Text("15")
                                            .font(.system(size:30))
                                            .fontWeight(.bold)
                                }.padding()
                                Text("Day(s)")
                                .foregroundColor(Color.black.opacity(0.8))
                            }.frame(height: 100)
    
    
                            VStack(alignment: .leading, spacing: 12){
                                HStack {
                                     Image("1")
                                        .resizable()
                                         .aspectRatio(contentMode: .fit)
                                         .frame(width: 170, height: 170)
                                 }
                               .background(Color.lairBackgroundGray)
                                //.padding(.bottom, 5)
                            }
                            .padding(.leading, 20)
                            Spacer(minLength: 0)
                        }
                        .padding(.horizontal, 20)
    
                    }//.frame(height: geometry.size.height)
                    .background(Color.lairBackgroundGray.edgesIgnoringSafeArea(.all))
                }
                //}
    
            }
    
    }[![enter image description here][1]][1]
    

您只需添加

.edgesIgnoringSafeArea(.all)

到您想要全屏显示的视图

重新创建整个视图并删除一些不必要的视图后,我解决了这个问题。