UIViewController In-Call Status Bar Issue
I've been looking for a solution for 3 days. I don't like this solution but didn't found better way how to fix it.
I'he got situation when rootViewController view has bigger height for 20 points than window, when I've got notification about status bar height updates I manually setup correct value.
Add method to the AppDelegate.swift
func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect) { if let window = application.keyWindow { window.rootViewController?.view.frame = window.frame } }
After that it works as expected (even after orientation changes).Hope it will help someone, because I spent too much time on this.
P.S. It blinks a little bit, but works.
I faced this problem too but after I put this method, problem is gone.
iOS has its default method willChangeStatusBarFrame
for handling status bar. Please put this method and check it .
func application(_ application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect) { UIView.animate(withDuration: 0.35, animations: {() -> Void in let windowFrame: CGRect? = ((window?.rootViewController? as? UITabBarController)?.viewControllers[0] as? UINavigationController)?.view?.frame if newStatusBarFrame.size.height > 20 { windowFrame?.origin?.y = newStatusBarFrame.size.height - 20 // old status bar frame is 20 } else { windowFrame?.origin?.y = 0.0 } ((window?.rootViewController? as? UITabBarController)?.viewControllers[0] as? UINavigationController)?.view?.frame = windowFrame })}
Hope this thing will help you.
Thank you
I had the same issue with the personnal hospot modifying the status bar.The solution is to register to the system notification for the change of status bar frame, this will allow you to update your layout and should fix any layout issue you might have.My solution which should work exactly the same for you is this :
In your view controller, in
viewWillAppear
suscribe to theUIApplicationDidChangeStatusBarFrameNotification
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(myControllerName.handleFrameResize(_:)), name: UIApplicationDidChangeStatusBarFrameNotification, object: nil)
Create your selector method
func handleFrameResize(notification: NSNotification) {self.view.layoutIfNeeded() }
Remove your controller from notification center in
viewWillDisappear
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIApplicationDidChangeStatusBarFrameNotification, object: nil)
You also need your modal to be in charge of the status bar so you should set
destVC.modalPresentationCapturesStatusBarAppearance = true
before presenting the view.
You can either implement this on every controller susceptible to have a change on the status bar, or you could make another class which will do it for every controller, like passing self to a method, keep the reference to change the layout and have a method to remove self. You know, in order to reuse code.