views:

32

answers:

1

Hi everyone

I have an issue with a UINavigationBar and its y-offset. The bar is displayed without a UINavigationController as superview, yet that should not matter. In the viewController where the navigation bar appears the setup looks like this:

    // Add Basic View
    CGRect viewFrame = [[UIScreen mainScreen] applicationFrame];
    UIView *myView = [[UIView alloc] initWithFrame:viewFrame];
 myView.backgroundColor = [UIColor greenColor];
 self.view = myView;
 [myView release];

    UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    .... add some Stuff to the bar...
    [self.view addSubview:myBar];
    [myBar release];

As I add the navigationBar as a chield View to self.view I assumed that origin.y = 0 would mean that the bar should get directly displayed below the status bar. This works as expected if I start the app on my iPad, rotate it once (or more) and then drill down to the view that is described above. In this case the UINavigationBar is displayed properly. Yet if I start my app and directly drill down to the controller described above (without rotating the device before this particular controller appears) the navigation bar slides 20 points below the status bar. But as soon as I rotate the device then, the bar is fine again. I have checked the viewFrame.origin.y value and it is 20 points in both situations, hence I do not understand why in one case the bar just seems to ignore the origin.y value of its superview but does not in the other.

I am really confused about this, has anybody else ever experienced such an issue?

Thanks a lot for your help!

Ps. I have also tried it with a UIToolbar, the problem is the same.

A: 

Yes. My solution is to set the "Full screen on launch" flag to on in Interface Builder for the window in the MainWindow-iPad.xib file. Then design your views as if the 20 pixel status bar were always displayed, so in my root view, I have a toolbar that is positioned 20px below the top of the screen in the content view.

lucius