iOS 7状态栏奇怪的行为

时间:2014-04-24 11:47:23

标签: ios objective-c ios7 uistatusbar ios7-statusbar

我正在为iPad应用程序使用UISplitViewController,我从StatusBar中得到一个奇怪的行为。

以下是我初始化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;

}

这就是我的应用程序的样子: iPad Status Bar overlapping

我已经在StackOverflow上阅读了关于同一问题的其他一些帖子,但没有得到太多结果。

有什么建议吗?

我没有使用Storyboard或XIB

1 个答案:

答案 0 :(得分:0)

假设您可以通过iPadDetailViewController中的媒体资源访问导航栏,则可以执行以下操作:

首先,在iPadDetailViewController.h中,实施UINavigationBarDelegate

@interface iPadDetailViewController : UIViewController <UINavigationBarDelegate>

然后,在iPadDetailViewController.m中,在self.navigationBar.delegate = self内设置viewDidLoad并添加以下方法:

- (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;
}