0

I have a UIViewControllerlaid out in a UIStoryboard that has the ability to hide its UIStatusBar. The views in this VC all include a constraint that keeps it's position relative to the topLayoutGuide.

I'm experiencing an issue where all the subviews jerk up 20 pixels when the status bar is hidden. I've logged the topLayoutGuide value on console, and it looks like it's length changes from 20 to 0 when hidden.

Is there any way to prevent the subviews from jerking 20px when hiding the status bar while keeping this constraint?

3254523
  • 3,016
  • 7
  • 29
  • 43

1 Answers1

0

The point of topLayoutGuide is that it dynamically moves with the status bar. You could try grabbing the length property of the topLayoutGuide when the view controller loads, and make a constraint that uses that value as its constant.

This would work only if the status bar is visible at load time, and it will break if the status bar gets taller, e.g. if you start a phone call. A better approach might be to use that value as a constant on a constraint that pins to top space to be >= that height from the top, and set an equal-to-that-length constraint at a lower priority, so it can get farther from the top of the screen if it needs to, but not any closer.

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82