We are showing a rectangle with a label over a table view when we encounter an error:
With this code:
// Fix location of message bar even as user scrolls table - per http://stackoverflow.com/q/7537858/47281
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let newY = self.tableView.contentOffset.y + self.navigationController!.navigationBar.frame.size.height + UIApplication.shared.statusBarFrame.height
// Show rectangle using 0 and newY ...
It works well but doesn't work in some cases such as when the Personal Hotspot is enabled. There is a gap between the Navigation Bar and the status rectangle:
What is the correct way to always position something under the Navigation Bar?
In the first case the status bar height is 20 but in the second case it's 40. In both cases the navigation bar and content offset are the same. Ie:
- Case #1: Offset: -64.0, Nav Bar height: 44.0 Status Bar Height: 20.0
- Case #2: Offset: -64.0, Nav Bar height: 44.0 Status Bar Height: 40.0
It seems like the offset isn't being increased based on the change in height in the status bar.
Update: See (my) accepted answer. I'm sure there is a better way.. please add to the thread if you know of one.