I have a UINavigationController
in which I define the navigationBar
for all UIViewControllers
as follows:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
I do this because there are some views,
for example: the profile view of a user, which needs to be transparant in order to show a backgroundImage
behind the username and profile picture.
This of course means the height of the navigationBar
becomes zero, so I need to set all my views accordingly and do this by pinning my topAnchors to view.safeAreaLayoutGuide.topAnchor
.
I continue by calculating the height of the navigationBar
. My code to get the height is:
navBarHeight = UIApplication.shared.statusBarFrame.height + (self.navigationController?.navigationBar.frame.height)!
This works like a charm. I can then create a custom UIView with the height set to the navBarHeight
, adding the color I want on my regular views and it works just fine.
However, it doesn't work when something comes up in the status bar.
For example: when I am calling, or when my personal homespot has active connection, when I am recording (voice or screen), a red, green or blue overlay is visible in the statusBar and the height increases. If I then open my app, the height is not right and the height of the navigationBar
view is too high, making my main content partly invisible on top.
How can I take this into account?