如何在Swift iOS应用中隐藏状态栏?

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


这不起作用:


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

}


呼啦一阵风
浏览 1104回答 3
3回答

慕运维8079593

您确实应该在视图控制器上实现preferredsStatusBarHidden:Swift 3及更高版本override var prefersStatusBarHidden: Bool {    return true}

幕布斯7119047

如果要在按钮水龙头上隐藏并恢复状态栏,而在显示和关闭幻灯片菜单,弹出窗口等时,则可以使用以下方法:隐藏状态栏:-UIApplication.shared.keyWindow?.windowLevel = UIWindowLevelStatusBar恢复状态栏:-UIApplication.shared.keyWindow?.windowLevel = UIWindowLevelNormal 
打开App,查看更多内容
随时随地看视频慕课网APP