Created
May 2, 2016 19:16
-
-
Save ldenoue/1fd2fca6c01c298bbef767d7f1811ec9 to your computer and use it in GitHub Desktop.
make opaque status bar even with self.navigationController.hidesBarsOnSwipe = YES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView { | |
self.navigationController.navigationBarHidden = NO; | |
} | |
-(void)opaqueStatusBar:(UIScrollView *)scrollView | |
{ | |
scrollView.delegate = self; | |
UIView *statusBarBg = [self.navigationController.view viewWithTag:3000]; | |
if (statusBarBg == nil) | |
{ | |
CGRect statusBarFrame = CGRectMake(0, 0, 1000, 20); | |
statusBarBg = [[UIView alloc] initWithFrame:statusBarFrame]; | |
statusBarBg.tag = 3000; | |
statusBarBg.backgroundColor = [UIColor whiteColor]; | |
[self.navigationController.view addSubview:statusBarBg]; | |
statusBarBg.hidden = [self shouldHideFakeStatusBar:self.view.frame.size]; | |
} | |
} | |
-(BOOL)shouldHideFakeStatusBar:(CGSize)size | |
{ | |
BOOL landscape = NO; | |
BOOL iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); | |
if (size.width > size.height) | |
landscape = YES; | |
BOOL hideFakeBar = landscape && !iPad; | |
return hideFakeBar; | |
} | |
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator | |
{ | |
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) | |
{ | |
BOOL hideFakeBar = [self shouldHideFakeStatusBar:size]; | |
UIView *view = [self.navigationController.view viewWithTag:3000]; | |
view.hidden = hideFakeBar; | |
NSLog(@"hiding fakebar=%d",hideFakeBar); | |
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) | |
{ | |
}]; | |
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment