我想移除屏幕顶部的状态栏。

这行不通:

func application
(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: NSDictionary?)
-> Bool
{
        application.statusBarHidden = true
        return true
}

我也试过:

func application
(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: NSDictionary?)
-> Bool
{
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    var controller = UIViewController()
    application.statusBarHidden = true
    controller.setNeedsStatusBarAppearanceUpdate()

    var view = UIView(frame: CGRectMake(0, 0, 320, 568))
    view.backgroundColor = UIColor.redColor()
    controller.view = view

    var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
    label.center = CGPointMake(160, 284)
    label.textAlignment = NSTextAlignment.Center
    label.text = "Hello World"
    controller.view.addSubview(label)

    self.window!.rootViewController = controller
    self.window!.makeKeyAndVisible()
    return true
}

当前回答

 override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(true);
    navigationController?.navigationBar.hidden = true // for navigation bar hide
    UIApplication.sharedApplication().statusBarHidden=true; // for status bar hide
}

其他回答

其实这是我自己发现的。我将添加我的解决方案作为另一种选择。

extension UIViewController {
    func prefersStatusBarHidden() -> Bool {
        return true
    }
}

在您的项目中“常规->部署信息->状态栏”样式 选择隐藏状态栏的复选标记 注意:-它隐藏状态栏在整个应用程序

在Swift 4.2中,它现在是一个属性。

override var prefersStatusBarHidden: Bool {
    return true
}

如果你更喜欢可视化的方法而不是编码,请使用以下方法: 在你的info.plist

简单地添加基于视图控制器的状态栏外观为NO

和状态栏最初隐藏为YES

在您的项目->通用->部署信息

状态栏风格:——

隐藏状态栏(iOS 10)