1

I'm using a UISplitViewController for an iPad app and I get a weird behavior from the StatusBar.

Here's how I initialize my RootViewController:

if(kIosVersionFloat >= 7.0)
        [application setStatusBarStyle:UIStatusBarStyleLightContent];
    [application setStatusBarHidden:NO];
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

        _rootNavigationVC = [[YTRootNavigationController alloc] init];
        _rootNavigationVC.navigationBarHidden = YES;

        NSShadow *shadow = [[NSShadow alloc] init];
        shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
        shadow.shadowOffset = CGSizeMake(0, 1);
        [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                               [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
                                                               shadow, NSShadowAttributeName,
                                                               [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];

        // RootViewController* firstVC = [[RootViewController alloc] init];

        detailViewController= [[iPadDetailViewController alloc]init];
        YTRootNavigationController *navC = [[YTRootNavigationController alloc]init];
        [navC pushViewController:detailViewController animated:NO];
        navC.navigationBarHidden = YES;
        _slidingVC = [[YTBaseViewController alloc] initWithViewClass:[YTSlidingContainerView class]];

        [_rootNavigationVC pushViewController:_slidingVC animated:NO];



        UISplitViewController* splitVC = [[UISplitViewController alloc] init];
        splitVC.viewControllers = [NSArray arrayWithObjects:_rootNavigationVC, navC, nil];

        _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        _window.rootViewController = splitVC;

}

And this is how my app looks like: iPad Status Bar overlapping

I have read a couple other posts on StackOverflow regarding the same issue but didn't get much result.

Any suggestions?

I am not using Storyboards or XIBs

Cezar
  • 55,636
  • 19
  • 86
  • 87
PonyLand
  • 115
  • 2
  • 10

1 Answers1

0

Assuming you have access to the Navigation Bar from a property in your iPadDetailViewController, you can do the following:

First, in your iPadDetailViewController.h, implement the UINavigationBarDelegate

@interface iPadDetailViewController : UIViewController <UINavigationBarDelegate>

Then, in iPadDetailViewController.m, set self.navigationBar.delegate = self inside viewDidLoad and add the following method:

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
    CGRect frame = self.navigationBar.frame;
    frame.origin = CGPointMake(0, [UIApplication sharedApplication].statusBarFrame.size.height);
    self.navigationBar.frame = frame;

    return UIBarPositionTopAttached;
}
Cezar
  • 55,636
  • 19
  • 86
  • 87