Can't Hide Status Bar—Swift 3, [duplicate]

我与影子孤独终老i 提交于 2019-12-17 07:26:06

问题


I usually hide the status bar with

override func prefersStatusBarHidden() -> Bool {
    return true
}

but Xcode is giving me an error, saying "Method does not override anything from its superclass".

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"


I also have "Hide Status Bar" checked in my Target's general settings:

but the status bar still shows up.


I found this method in another Stack Overflow answer

UIApplication.shared.setStatusBarHidden(true, with: .none)

but that doesn't hide the status bar either.


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?

Note: The status bar shows up on Simulator devices and physical devices, all running iOS 10.


回答1:


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.



来源:https://stackoverflow.com/questions/38876249/cant-hide-status-bar-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!