简体   繁体   中英

Swift Status bar height change

Using Xcode 8 and Swift 2.3.

In my app when I get WhatsApp call or enable hotspot,
Status bar height changes and alignment gets altered.

How do I refresh the screen when status bar height changes,
So screen gets adjusted.

I came across these two delegate methods but no idea how to use this for my requirement.

func application(application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect)
{
    print("Frame Change old")
}

func application(application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect)
{
    print("Frame Change new")


}

Those delegates must be added to the AppDelegate.swift, if I'm not mistaken.

Then you need to resize the Window putting this code inside the new status bar delegate

if let window = self.window {
    window.clipsToBounds = true
    window.frame = CGRect(x: 0, y: newStatusBarFrame.size.height, width: window.frame.size.width, height: window.frame.size.height);
    window.bounds = CGRect(x: 0, y: 0, width: window.frame.size.width, height: window.frame.size.height);
}

Haven't tested the code so I hope it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM