11

I deal with autolayout set up in Interface Builder. I want to not offset views that are pinned to top layout guide when I hide status bar in runtime.

I have discovered that myViewController.topLayoutGuide.length changes from 20 to 0 when hiding status bar. How to prevent it? Or (as workaround) how to set up fullscreen view for various window sizes without pin to top layout guide?

Some code to describe my situation:

Log(@"frame: %@, top: %.0f", NSStringFromCGRect(myViewController.myView.frame), self.topLayoutGuide.length);
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Log(@"frame: %@, top: %.0f", NSStringFromCGRect(myViewController.myView.frame), self.topLayoutGuide.length);

Output:

frame: {{40, 24}, {240, 40}}, top: 20
frame: {{40, 4}, {240, 40}}, top: 0
brigadir
  • 6,874
  • 6
  • 46
  • 81
  • Not totally clear on what you're trying to achieve. Are you trying to have the view show the elements at a fixed location, no matter if the status bar is showing or not? Or is this an iOS6/7 switching issue? You can also hide the status bar in IB if that is causing problems when you lay out components vs runtime result. – Ben May 22 '14 at 16:39
  • I hide status bar in runtime and at that moment UI shifts. The reason is in `topLayoutGuide`. I want to keep UI at its position when status bar hides. – brigadir May 22 '14 at 20:16
  • Are you showing the view and -then- getting rid of the status bar, or are you telling the status bar not to appear before showing the view? – Ben May 23 '14 at 00:20
  • I'm afraid we are talking about different things... – brigadir May 23 '14 at 05:49

1 Answers1

19

The topLayoutGuide property is readonly and you can't prevent it from changing.

You can pin your items not to the topLayoutGuide but to the superview. That should resolve your problem.

enter image description here

deramko
  • 2,807
  • 1
  • 18
  • 27