Last active
August 29, 2015 14:12
-
-
Save ajjames/4a87921d691bad0f5cec to your computer and use it in GitHub Desktop.
TabBar hiding
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
//.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