Last active
August 29, 2015 14:01
-
-
Save tapsandswipes/7e10da769b07c030c1e4 to your computer and use it in GitHub Desktop.
Show/Hide chrome in UINavigationViewController on iOS 7
This file contains hidden or 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
@property (nonatomic, assign, getter = isChromeHidden) BOOL chromeHidden; | |
- (BOOL)prefersStatusBarHidden { | |
return self.isChromeHidden; | |
} | |
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { | |
return UIStatusBarAnimationSlide; | |
} | |
- (void)syncStatusBarWithDuration:(CGFloat)duration { | |
BOOL hideStatusBar = [self prefersStatusBarHidden]; | |
[UIView animateWithDuration:(26.0 * duration / 64.0) | |
delay:(hideStatusBar ? 0.0 : 37.0 * duration / 64.0) | |
options:UIViewAnimationOptionBeginFromCurrentState | (hideStatusBar ? UIViewAnimationOptionCurveEaseIn : UIViewAnimationOptionCurveEaseOut) | |
animations:^{ | |
[self setNeedsStatusBarAppearanceUpdate]; | |
} | |
completion:nil | |
]; | |
} | |
- (void)setChromeHidden:(BOOL)hidden { | |
if (_chromeHidden != hidden) { | |
_chromeHidden = hidden; | |
[self syncStatusBarWithDuration:UINavigationControllerHideShowBarDuration]; | |
[self.navigationController setToolbarHidden:hidden animated:YES]; | |
[self.navigationController setNavigationBarHidden:hidden animated:YES]; | |
} | |
} | |
- (void)toggleChrome { | |
[self setChromeHidden:!self.isChromeHidden]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment