Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is my navigationBar under my status bar?

http://www.irovr.com/stackOverflow/overlap.png

- (void)viewDidLoad {
        [super viewDidLoad];
        [self setWantsFullScreenLayout:YES];
        [mainScrollView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMainScrollTap:)]];
    }

- (void)onMainScrollTap:(id)sender {
    if(self.navigationController.navigationBar.hidden){
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.navigationController setToolbarHidden:NO animated:NO];
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    }else{
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [self.navigationController setToolbarHidden:YES animated:YES];
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    }
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.toolbar.translucent = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self.navigationController setToolbarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.toolbar.translucent = NO;
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [self.navigationController setToolbarHidden:YES animated:NO];
}
like image 670
E-Madd Avatar asked Jul 11 '10 07:07

E-Madd


2 Answers

It seems that hiding the status bar and navigation bar at the same time causes this problem. I was able to resolve it by hiding/showing the navigation bar with performSelector:withObject:afterDelay, even with a delay of 0

like image 156
E-Madd Avatar answered Sep 28 '22 08:09

E-Madd


Using "performSelector" will work.

However, some may find it easier to add the following to "viewWillDisappear" even if there is already a statement that unhides the navigation bar.

[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
like image 22
Hermann Klecker Avatar answered Sep 28 '22 08:09

Hermann Klecker