I decided to resize this UITabBarControllerto get the tab bar off-screen:
- (void)setTabBarHidden:(BOOL)hidden
{
CGRect frame = self.originalViewFrame;
if (hidden)
{
frame.size.height += self.tabBar.size.height;
}
self.view.frame = frame;
}
Then you can add KVO to your scroll view:
[scrollView addObserver:self
forKeyPath:@"contentOffset"
options:NSKeyValueObservingOptionOld
context:nil];
And hide / show scroll tab bar:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
CGPoint oldOffset = [(NSValue *)change[NSKeyValueChangeOldKey] CGPointValue];
if (!_hidesBarsOnScroll || _scrollView.contentOffset.y == oldOffset.y)
return;
if (_barsHidden &&
scrollView.contentOffset.y < oldOffset.y &&
scrollView.contentOffset.y + scrollView.bounds.size.height < scrollView.contentSize.height)
{
[self.navigationController setNavigationBarHidden:NO
animated:YES];
[self.tabBarController setTabBarHidden:NO
animated:YES];
_barsHidden = NO;
}
if (!_barsHidden &&
scrollView.contentOffset.y > 0 &&
scrollView.contentOffset.y > oldOffset.y)
{
[self.navigationController setNavigationBarHidden:YES
animated:YES];
[self.tabBarController setTabBarHidden:YES
animated:YES];
_barsHidden = YES;
}
}
You can take a look at this implementation here .
source
share