I also ran into this problem and solved it by checking the size of the status bar when opening the application, and if it is 40 points, then it listens for UIApplicationDidChangeStatusBarFrame
notifications, and when it happens, it moves the frame views to .zero
.
For example, in Swift 4:
var sbshown: Bool = false override func viewDidLoad() { super.viewDidLoad() //check height of status bar when app opens, and set a boolean if open let sbheight = UIApplication.shared.statusBarFrame.height NSLog("status bar height %f", sbheight) if (sbheight == 40) { sbshown = true } //set up to receive notifications when the status bar changes let nc = NotificationCenter.default nc.addObserver(forName: NSNotification.Name.UIApplicationDidChangeStatusBarFrame, object: nil, queue: nil, using: statusbarChange) }
Then we implement the method of resizing and changing the position when the status bar disappears:
func statusbarChange(notif: Notification) -> Void { if (sbshown) { sbshown = false self.view.frame.origin = .zero self.view.frame.size.height = UIScreen.main.bounds.height } }
So, re-positioning should occur only if the panel was shown when the application was opened, and not if the panel is displayed and hidden when the application is already open.
source share