首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么SwiftUI不在这个fullScreenCover上隐藏我的状态栏?

问为什么SwiftUI不在这个fullScreenCover上隐藏我的状态栏?
EN

Stack Overflow用户
提问于 2020-12-10 12:00:40
回答 1查看 1.3K关注 0票数 1

我的密码在下面。.statusBar(hidden: true)应该在另一个地方吗?它是否依赖于一些我不知道的@Environment?

代码语言:javascript
复制
import SwiftUI

struct ContentView: View {
    
    @State private var isShowingFullScreenModal = false
    
    var body: some View {
        Text("Show Modal")
            .font(.title)
            .foregroundColor(.white)
            .frame(width: 180, height: 44)
            .padding()
            .background(Color.blue)
            .cornerRadius(12)
            .onTapGesture {
                isShowingFullScreenModal = true
            }
            .fullScreenCover(isPresented: $isShowingFullScreenModal) {
                Color.green
                    .ignoresSafeArea(.all)
                    .onTapGesture {
                        isShowingFullScreenModal = false
                    }
            }
    }
}

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


struct GreenCover: View {
    
    @Environment(\.presentationMode) var presentationMode
    
    var body: some View {
        
        ZStack {
            Color.green
                .ignoresSafeArea(.all)
            VStack{
                HStack{
                    Spacer()
                    Image(systemName: "xmark.circle.fill")
                }
                Spacer()
            }
        }
        .statusBar(hidden: true)
    }
    
}
EN

回答 1

Stack Overflow用户

发布于 2020-12-11 21:17:24

有时,在我们的应用程序中,我们需要隐藏状态栏、导航栏和其他东西,并且只显示我们想要显示的内容。要使用快速语言在iOS应用程序中隐藏状态栏,我们需要完成非常基本的步骤。

方法1

在info.plist文件本身中,添加另一个名为Status bar is initially hidden的键,并将其设置为YES。

我在这个方法中注意到的是,状态栏只在应用程序启动时隐藏。

方法2

转到应用程序委托文件,并添加以下代码行:UIApplication.shared.isStatusBarHidden = true

这在iOS 13上是不可取的。

方法3

您也可以添加这一行代码,状态栏将被隐藏。

代码语言:javascript
复制
.edgesIgnoringSafeArea(.all)
.statusBar(hidden: true)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65234125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档