为什么SwiftUI没有在这个全屏上隐藏我的状态栏?
我的代码如下。.statusBarhidden:true是否应位于其他位置?这取决于我不知道的某个@环境吗为什么SwiftUI没有在这个全屏上隐藏我的状态栏?,swiftui,statusbar,Swiftui,Statusbar,我的代码如下。.statusBarhidden:true是否应位于其他位置?这取决于我不知道的某个@环境吗 import SwiftUI struct ContentView: View { @State private var isShowingFullScreenModal = false var body: some View { Text("Show Modal") .font(.title
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)
}
}
这是一个固定变量。使用Xcode 12.1/iOS 14.1进行测试
.onTapGesture {
isShowingFullScreenModal = true
}
.statusBar(hidden: isShowingFullScreenModal) // << here !!
.fullScreenCover(isPresented: $isShowingFullScreenModal) {
这是一个固定变量。使用Xcode 12.1/iOS 14.1进行测试
.onTapGesture {
isShowingFullScreenModal = true
}
.statusBar(hidden: isShowingFullScreenModal) // << here !!
.fullScreenCover(isPresented: $isShowingFullScreenModal) {
有时在我们的应用程序中,我们需要隐藏状态栏、导航栏和其他东西,只显示我们想要显示的内容。要使用swift语言在iOS应用程序中隐藏状态栏,我们需要执行非常基本的步骤 方法1 在info.plist文件本身中,添加另一个名为“状态栏”的键最初是隐藏的,并将其设置为“是” 我注意到,这种方法只在应用程序启动时才隐藏状态栏 方法2 转到应用程序代理文件,添加以下代码行:UIApplication.shared.isStatusBarHidden=true 这在iOS 13上被弃用 方法3 您也可以添加这行代码,状态栏将被隐藏
.edgesIgnoringSafeArea(.all)
.statusBar(hidden: true)
有时在我们的应用程序中,我们需要隐藏状态栏、导航栏和其他东西,只显示我们想要显示的内容。要使用swift语言在iOS应用程序中隐藏状态栏,我们需要执行非常基本的步骤 方法1 在info.plist文件本身中,添加另一个名为“状态栏”的键最初是隐藏的,并将其设置为“是” 我注意到,这种方法只在应用程序启动时才隐藏状态栏 方法2 转到应用程序代理文件,添加以下代码行:UIApplication.shared.isStatusBarHidden=true 这在iOS 13上被弃用 方法3 您也可以添加这行代码,状态栏将被隐藏
.edgesIgnoringSafeArea(.all)
.statusBar(hidden: true)
如果你想回答我的问题,我不确定这是否有帮助。这只是一个一般性的解释。我的原始代码没有。statusBarhidden:true。如果在第3点下,您的意思是特别添加.edgesIgnoringSafeArea.all,那么明确地说出来会很有帮助。或者你的意思是两行都必须加上?按那个顺序?我的代码在Z堆栈下有.ignoresSafeArea.all。你的意思是忽略。。。代码必须位于隐藏状态栏之前。。。密码我真的很抱歉,但我看不出这是如何回答我的问题的。你能说得更清楚些吗?如果你想回答我的问题,我不确定这是否有帮助。这只是一个一般性的解释。我的原始代码没有。statusBarhidden:true。如果在第3点下,您的意思是特别添加.edgesIgnoringSafeArea.all,那么明确地说出来会很有帮助。或者你的意思是两行都必须加上?按那个顺序?我的代码在Z堆栈下有.ignoresSafeArea.all。你的意思是忽略。。。代码必须位于隐藏状态栏之前。。。密码我真的很抱歉,但我看不出这是如何回答我的问题的。你能说清楚点吗?