3

I am using a UITabBarController to switch between two view controllers. The first view controller looks fine but the second view controller has a white gap between the status bar and the root view equaling the height of the status bar.

gap status bar

Here is the nib file for the second view controller. I've turned on the simulated status bar and tab bar and placed the UIImageView flush between those two bars. My code does nothing to change the position of the UIImageView.

nib

I noticed that the Facebook app sometimes has this problem when returning from viewing a photo to the news feed. My problem is similar, except it happens 100% of the time. What could be the problem?

JoJo
  • 19,587
  • 34
  • 106
  • 162

1 Answers1

1

What is the origin of your containing view and image view? If you have manually adjusted these to compensate for the status bar and then your nib is set to want full screen, this may cause it to be one status bar's height below the top of it's content view, which looks like the situation you have. The origins of both views should be (0,0), I think.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • I did not manually set the origin of any view from the nib file. I really can't think of anything special I did. This is the default UITabBarController you get when you create a new project. – JoJo Sep 26 '11 at 21:38
  • You said in your question that you placed the image view flush between the two bars - so what is the origin of it? – jrturton Sep 27 '11 at 05:43
  • I positioned the UIImageView with Interface Builder only. IB shows `x:0, y:0, w:320, h:411`. Every line in the autosizing GUI is solid, however I don't see it taking effect. When I rotate my phone, the UIImageView does not autosize; only the UISwitch does. – JoJo Sep 27 '11 at 17:30
  • I logged out the frame of the image and strangely it said `x:0, y:0, w:0, h:0`. How can it be a 0x0 rectangle? `- (void)viewDidAppear:(BOOL)animated { NSLog(@"x:%d, y:%d, w:%d, h:%d", self.img.frame.origin.x, self.img.frame.origin.y, self.img.frame.size.width, self.img.frame.size.height); }` – JoJo Sep 27 '11 at 19:13
  • I've created a test app here and the containing view has origin of 0,20, the image view of 0,0. I literally dropped in the image view and that was it. I don't see the gap and it autorotates fine. Do you ever hide or show the status bar in code? – jrturton Sep 27 '11 at 19:54
  • I think the problem was related to the `AVCaptureVideoPreviewLayer` subview of the `UIImageView`. I had to do some voodoo to stretch the preview to fill the parent image. Apple's official documentation was wrong. I had to use this solution: http://stackoverflow.com/questions/5117770/avcapturevideopreviewlayer – JoJo Sep 27 '11 at 19:58