问题描述
我通常会隐藏状态栏
override func prefersStatusBarHidden() -> Bool {
return true
}
但Xcode给我一个错误,说方法不会覆盖其超类中的任何内容。
but Xcode is giving me an error, saying "Method does not override anything from its superclass".
如果我删除覆盖
,Xcode会给出不同的错误:使用Objective-C选择器'prefersStatusBarHidden'的方法'prefersStatusBarHidden()'与来自超类'UIViewController'的'prefersStatusBarHidden'的getter冲突,使用相同的Objective-C选择器
If I delete the override
, Xcode gives a different error: "Method 'prefersStatusBarHidden()' with Objective-C selector 'prefersStatusBarHidden' conflicts with getter for 'prefersStatusBarHidden' from superclass 'UIViewController' with the same Objective-C selector"
我还在Target的常规设置中选中了隐藏状态栏:
I also have "Hide Status Bar" checked in my Target's general settings:
但状态栏仍然显示。
我发现另一个Stack Overflow回答中的这个方法
I found this method in another Stack Overflow answer
UIApplication.shared.setStatusBarHidden(true, with: .none)
但是这也不会隐藏状态栏。
but that doesn't hide the status bar either.
在Xcode 8 Beta 1中,我使用了第一种和第二种方法,它可以隐藏状态栏(第一种方法没有返回错误)。我现在可以用Xcode 8 Beta 4隐藏状态栏吗?
In Xcode 8 Beta 1, I used the first and second methods, which worked to hide the status bar (the first method did not return an error). What can I do now to hide the status bar, with Xcode 8 Beta 4?
注意:状态栏显示在Simulator设备和物理设备上,所有设备都运行iOS 10 。
Note: The status bar shows up on Simulator devices and physical devices, all running iOS 10.
推荐答案
我们需要在Swift 3上覆盖属性本身(这是Xcode 8 Beta 4中的新功能):
We need to override the property itself on Swift 3 (this is new in Xcode 8 Beta 4):
override var prefersStatusBarHidden: Bool {
return true
}
另一个例子也可以得到和
for another example also you can get here and here
有关此更改的详细信息以及为何需要,请参阅。
For more on what this change is and why it's necessary, see Matt's great answer on this.
这篇关于无法隐藏状态栏-Swift 3,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!