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)view开发者_Python百科WillDisappear:(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];
}
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
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];
Your view is set too large, so it's getting drawn underneath the status bar. If you're using Interface Builder to create it as a .xib, you need to enabled the setting for the status bar under "Simulated Interface Elements", or just reduce the height of your view manually.
- (void)fixNavigationBarUnderStatusbarBug
{
//This method fix bug! Don't cut it
//Bug: Statusbar hide navigationBar after device rotation.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[center addObserverForName:UIDeviceOrientationDidChangeNotification object:nil
queue:mainQueue usingBlock:^(NSNotification *note) {
UIApplication *currentApplication = [UIApplication sharedApplication];
if (currentApplication.statusBarHidden) {
[currentApplication setStatusBarHidden:NO];
double delayInSeconds = .1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[currentApplication setStatusBarHidden:YES];
});
}
}];
}
}
精彩评论