Reputation: 99
Whenever I am on a call the green call status bar is being put on top of my navigation bar. The same applies with the hotspot status bar.
Currently using latest swift
I am guessing I need to use:
func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect) {
}
I am not having any luck with what I need to do with it
Upvotes: 3
Views: 460
Reputation: 2228
You were on the right track with listening for frame changes in your delegate.
First register your view controller (or whichever class needs to adjust to the status bar frame change)
//
// In some class that needs to update for status bar changes
//
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: #selector(statusBarFrameWillChange:),
name: UIApplicationWillChangeStatusBarFrameNotification,
object: nil)
Second, in your app delegate, add the following method (similar to your approach) to be called when the status bar is going to change
optional func application(_ application: UIApplication,
willChangeStatusBarFrame newStatusBarFrame: CGRect)
Finally, from within here you can simply post a notification to the system alerting all listening observers of this change in order to handle the status bars frame change:
func post(_ notification: Notification)
In your observer, within the statusBarFrameWillChange
method that I chose to be called when the notification is posted, simply adjust your navigation bar's frame either down or up with respect to the status bars frame.
Upvotes: 2