Skip to content

Instantly share code, notes, and snippets.

@ajjames
Last active August 29, 2015 14:12
Show Gist options
  • Save ajjames/4a87921d691bad0f5cec to your computer and use it in GitHub Desktop.
Save ajjames/4a87921d691bad0f5cec to your computer and use it in GitHub Desktop.
TabBar hiding
//.h
@interface TabBarHidingCollectionViewController : UICollectionViewController
@end
//.m
@interface TabBarHidingCollectionViewController ()
@property (nonatomic) CGFloat lastOffsetY;
@end
@implementation TabBarHidingCollectionViewController
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.lastOffsetY = scrollView.contentOffset.y;
}
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
CGFloat currentOffsetY = scrollView.contentOffset.y;
BOOL shouldHide = (targetContentOffset->y <= 0.0)? false : (self.lastOffsetY < currentOffsetY);
[self showHideTabBar:shouldHide];
}
-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
[self showHideTabBar:NO];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self showHideTabBar:NO];
}
-(void)showHideTabBar:(BOOL)isHidden
{
if (IS_PHONE)
{
GGIAppDelegate *mainApp = (GGIAppDelegate*)[UIApplication sharedApplication].delegate;
UITabBarController *tabBar = mainApp.tabBarController;
[tabBar setHidden:isHidden];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment