我的密码在下面。.statusBar(hidden: true)应该在另一个地方吗?它是否依赖于一些我不知道的@Environment?
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)
}
}发布于 2020-12-11 21:17:24
有时,在我们的应用程序中,我们需要隐藏状态栏、导航栏和其他东西,并且只显示我们想要显示的内容。要使用快速语言在iOS应用程序中隐藏状态栏,我们需要完成非常基本的步骤。
方法1
在info.plist文件本身中,添加另一个名为Status bar is initially hidden的键,并将其设置为YES。
我在这个方法中注意到的是,状态栏只在应用程序启动时隐藏。
方法2
转到应用程序委托文件,并添加以下代码行:UIApplication.shared.isStatusBarHidden = true
这在iOS 13上是不可取的。
方法3
您也可以添加这一行代码,状态栏将被隐藏。
.edgesIgnoringSafeArea(.all)
.statusBar(hidden: true)https://stackoverflow.com/questions/65234125
复制相似问题