相关疑难解决方法(0)

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

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

这不起作用:

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

我也尝试过:

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 …
Run Code Online (Sandbox Code Playgroud)

iphone ios ios7 swift

191
推荐指数
13
解决办法
13万
查看次数

无法隐藏状态栏-Swift 3,

我经常隐藏状态栏

override func prefersStatusBarHidden() -> Bool {
    return true
}
Run Code Online (Sandbox Code Playgroud)

但Xcode给了我一个错误,说"方法不会覆盖其超类中的任何内容".

如果我删除了override,Xcode会给出一个不同的错误:"方法"prefersStatusBarHidden()'与Objective-C选择器'prefersStatusBarHidden'与来自超类'UIViewController'的'prefersStatusBarHidden'的getter冲突与同一个Objective-C选择器"


我还在Target的常规设置中选中了"隐藏状态栏":

在此输入图像描述

但状态栏仍然显示.


我在另一个Stack Overflow答案中找到了这个方法

UIApplication.shared.setStatusBarHidden(true, with: .none)
Run Code Online (Sandbox Code Playgroud)

但这也不会隐藏状态栏.


在Xcode 8 Beta 1中,我使用了第一种和第二种方法,它们可以隐藏状态栏(第一种方法没有返回错误).现在我可以用Xcode 8 Beta 4隐藏状态栏吗?

注意:状态栏显示在模拟器设备和物理设备上,均运行iOS 10.

xcode ios swift swift3

47
推荐指数
1
解决办法
3万
查看次数

标签 统计

ios ×2

swift ×2

ios7 ×1

iphone ×1

swift3 ×1

xcode ×1