Skip to content

Instantly share code, notes, and snippets.

@chrishulbert
Created March 5, 2015 03:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishulbert/2ea6bd044cc082b24f96 to your computer and use it in GitHub Desktop.
Save chrishulbert/2ea6bd044cc082b24f96 to your computer and use it in GitHub Desktop.
Allows you to slide your navigation bar away when hiding it
// Header:
@interface MyNavigationController : UINavigationController
- (void)setNavigationBarSlidAway:(BOOL)slidAway animated:(BOOL)animated;
@end
// Implementation:
static int kNavHeight = 64;
@implementation MyNavigationController {
BOOL _navBarSlidAway;
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self layoutNavBar];
}
- (void)layoutNavBar {
self.navigationBar.frame = CGRectMake(0,
_navBarSlidAway ? -kNavHeight : 0,
self.view.bounds.size.width,
kNavHeight);
}
- (void)setNavigationBarSlidAway:(BOOL)slidAway animated:(BOOL)animated {
_navBarSlidAway = slidAway;
if (animated) {
[UIView animateWithDuration:.3 animations:^{
[self layoutNavBar];
}];
} else {
[self layoutNavBar];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment