Skip to content

Instantly share code, notes, and snippets.

@tapsandswipes
Last active August 29, 2015 14:01
Show Gist options
  • Save tapsandswipes/7e10da769b07c030c1e4 to your computer and use it in GitHub Desktop.
Save tapsandswipes/7e10da769b07c030c1e4 to your computer and use it in GitHub Desktop.
Show/Hide chrome in UINavigationViewController on iOS 7
@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