3

I am having status bar issues. I have a UIViewController, this has a container view which embeds a UITabBarController inside that UIViewController.

When enabling the status bar in my app using View controller-based status bar appearance = YES in my Info.plist, it acts as normal, the root UIViewController displays the status bar as you expect.

However, it is causing the UITabBarController in the container view to push my view contents down by 20 pixels, leaving a gap at the top of my tabbar view for where it thinks the status bar should be.

But of course the status bar isn't shown there because its shown at the top of the screen where it normally is. So it is effectively just adding a gap in my container view.

halfer
  • 19,824
  • 17
  • 99
  • 186
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253

3 Answers3

7

Turns out the topLayoutGuide was pushing my view down by 20 pixels for the status bar. Because it was expecting a status bar, the topLayoutGuide adds this 20 pixel space.

In my storyboard the topmost subview of my view controller had a constraint to fix it to the top of my view. This constraint was the view top equal to topLayoutGuide bottom.

This meant that when the topLayoutGuide added the 20 pixel space, my entire view was offset by that.

By changing the constraint to fix to the topLayoutGuide top instead, the space created is now just sitting underneath my normal subviews not causing any problems.

Josh Kahane
  • 16,765
  • 45
  • 140
  • 253
1

Having similarly had this problem myself, the issue is that whatever view is in your tab bar controller, has a constraint that matches the top of the controller to the toplayoutguide. The top layout guide for tab controllers in container views will still have a length of 20. One solution that works is to remove this constraint, and have the views have the same top as the parent view controller view, or size the height / center-y-to-container to be the same as the parent view controller's view (parent being the view controller in the tab, not the view controller that you are embedding the tab bar controller in).

TabBarController --> RootViewController --> RootVCView --> subview

Make subview.height == to RootVCView.height, and subview.centerY == rootVCView.centerY.

This is for the simple case that you only have one subview, you need to do this for which ever subview(s) have the top constraint. Without knowing more about your storyboard layout, this is the best solution I can provide. Hope it helps!

rvijay007
  • 1,357
  • 12
  • 20
  • Thanks rvijay007. While your solution didn't fit the bill it lead me in the right direction. I hadn't thought of the `topLayoutGuide`. I've left my answer, all resolved, thank you! – Josh Kahane Jun 13 '14 at 21:12
0

Add constraint of 'Top Space To:' not with "topLayoutGuide" for your container view and it will fix the issue

parth
  • 853
  • 11
  • 18