当prefersStatusBarHidden()设置为true时,不会隐藏状态栏的Swift / iOS 8

时间:2015-06-07 18:50:10

标签: ios swift

我在iOS应用项目中有以下设置: 未选中“隐藏状态栏”。

可以在部署信息下的常规项目设置中找到。

在AppDelegate.swift中:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        window = UIWindow(frame: UIScreen.mainScreen().applicationFrame)

        window!.rootViewController = ViewController()
        window!.makeKeyAndVisible()
        // Override point for customization after application launch.
        return true
    }
...

在ViewController.swift中:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        view.backgroundColor = UIColor.blueColor()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

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

我得到了以下结果(不幸的是,我是新成员,没有足够的代表发布图片): 大多数屏幕都是蓝色的,除了顶部(状态栏应显示的位置),它是黑色的。

有人可以向我解释为什么顶部是黑色的,以及如何修复它(例如把它变成蓝色)?

1 个答案:

答案 0 :(得分:2)

顶部是黑色的,因为这条线错了:

window = UIWindow(frame: UIScreen.mainScreen().applicationFrame)

应该是:

window = UIWindow(frame:UIScreen.mainScreen().bounds)