0

I am using a UINavigationController as my root view and pushing UIViewController instances onto the stack.

My view controllers all derived from a base, which draws a radial gradient background during viewWillAppear.

With the NavigationBar.translucent property set to NO/false the first view controller pushed onto the stack has it's view frame's y component set to the height of the NavigationBar, effectively creating blank space between the nav bar and the view's contents. Subsequent view controller's pushed onto the stack do not have this issue.

I overrode pushViewController in my navigation controller and set the NavigationBar.translucent to YES if the navigationController.viewControllers array was empty. Doing this gets rid of the space on the first view controller but this isn't really what I want as I don't want translucent nav bars.

I printed out the view's frame during various life cycle phases and only the first view has it's y component modified, additional views have the frame y set to 0. I am not modifying the root view frame in any of the view controllers.

My question is, what am I doing wrong? I know it is an issue with the first view controller because of my override but since I don't see tons of posts about this I assume I did something wrong.

My question is similar to this: Container View getting pushed down as if it had a UINavigationBar?

Community
  • 1
  • 1
Cameron
  • 133
  • 3
  • 7

1 Answers1

0

You need to set Adjust Scroll View Insets to false. To fix it try:

InterfaceBuild: https://stackoverflow.com/a/26567240/846780

Code: self.automaticallyAdjustsScrollViewInsets = NO;

Community
  • 1
  • 1
Klevison
  • 3,342
  • 2
  • 19
  • 32
  • That link does look like my issue though I am not using a scroll view. Setting this property does not seem to change the behavior. I worked around it by drawing the background in viewDidLoad but not really satisfied with that behavior. – Cameron Sep 02 '16 at 20:59
  • Here is a screenshot: dl.dropboxusercontent.com/u/6349532/screen.png (The black along the top is the gap.) – Cameron Sep 04 '16 at 19:34