ios - iPhone 11 Simulator 中的主页 View 背景颜色未全屏显示

标签 ios xcode background swiftui ios-simulator

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

  • 在 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))
        }
    }
    
    下面是我的另一个 View ,它基本上作为主视图的一部分在屏幕上绘制。请原谅我在这里放了这么多代码,但想确定是不是因为 View1 -
    结构 View 1:查看{
    @State 变量索引 = 0
    var body: 一些 View {
    // ScrollView {
    GeometryReader { 几何输入
    堆栈{
    堆栈{
    堆栈{
    ZStack{
    圆圈()
    .trim(从:0,到:1)
    .stroke(Color.lairDarkGray.opacity(0.09), style: 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)
    
    到您想要全屏显示的 View

    关于ios - iPhone 11 Simulator 中的主页 View 背景颜色未全屏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62720728/

    相关文章:

    ios - iOS,如何使用NSArray确定plist中的字符串列表中的单词长度

    iphone - 加载 View 后隐藏状态栏留下黑条

    ios - SKReferenceNode 缩放后 Swift 碰撞不起作用

    背景更改不适用于 Windows Phone 8

    html - 我想让背景图片不显示在IE中。我怎么做?

    language-agnostic - round() 和 trunc() 函数有什么区别?

    C++:如何在 iOS 中已有的 MFC 应用程序中重用加密的 Sqlite 数据库

    ios - 无法识别完成 block 返回类型

    ios - 如何在 swift 4 中使用 json 对象发送 json 数据

    objective-c - 模拟器工作,设备不工作?