When on a phone call while in the iOS App Store the status bar changes from 40pt tall to 20pt tall when reading an article. How do I do this in my app?

- 7,647
- 5
- 55
- 94
-
Not possible to programmatically increase status bar I'm afraid – Niall Kiddle Mar 09 '18 at 15:40
1 Answers
this is really an interesting question, took me sometimes to figure it out.
if you notice app store in such viewcontroller didn't have a status bar, which means the green bar should not be shown at all. this is the first hint.
you can access the status bar by
UIApplication.shared.value(forKey: "statusBarWindow") as! UIWindow
according to point number one this means the status bar is not hidden but actually its
statusBarWindow.frame.origin.y
just shifted up.please not you need to handle iPhone x separately
please make sure the status bar is not hidden
note that this is not the only right way, right now you have the view itself, you can change the origin or size or even try to get what inside this view and hide them or change their frames too etc.
here is an example how you can do it.
class ViewController: UIViewController {
var isHidden:Bool = false
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 0.5) { () -> Void in
let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as! UIWindow
statusBarWindow.frame = CGRect(x: 0, y: -20, width: statusBarWindow.frame.size.width, height: 40.0)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override var prefersStatusBarHidden: Bool{
return isHidden
}
}
also attached an image with the result of this code, hopefully, this answer work for you too.

- 190
- 1
- 14