Xcode 8.2:Swift3-如何隐藏状态栏?

时间:2016-12-21 05:34:12

标签: ios swift xcode

所有人都试图用Xcode 8.2和swift 3隐藏状态栏。但是我无法隐藏它。

enter image description here

enter image description here

以及

enter image description here

3 个答案:

答案 0 :(得分:14)

您可以通过两种方式解决此问题

  

选项1 。在private HttpServletRequest request; private static ThreadLocal<WebContext> wcHolder = new ThreadLocal<WebContext>(); private WebContext(){} public static WebContext newInstance(HttpServletRequest request){ //case 1:correct // WebContext wc = new WebContext(); // wc.request = request; //case 2:incorrect //(to resolve multiply creat WebContext object within one request) WebContext wc = wcHolder.get(); if(wc==null){ wc = new WebContext(); wc.request = request; wcHolder.set(wc); } return wc; } 方法

中尝试此操作
didFinishLaunchingWithOptions
  

选项2 。覆盖func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { UIApplication.shared.isStatusBarHidden = true return true }

中的prefersStatusBarHidden功能
UIViewController

注意:您致电override var prefersStatusBarHidden : Bool { return true } 它应为override func prefersStatusBarHidden

答案 1 :(得分:1)

在swift 3中使用它,

override var prefersStatusBarHidden: Bool {  
    return true  
}

Reference link

答案 2 :(得分:1)

在视图控制器中覆盖prefersStatusBarHidden

override var prefersStatusBarHidden : Bool {
        return true
    }

如果状态栏应该隐藏,则为true;如果应显示状态栏,则为false。

参考apple doc link