Xcode/iOS: How to hide Navigation- AND ToolBar on scroll down?
ios, navigationbar, toolbar, xcode
Solution
The accepted answer does not work for me, as `scrollViewWillBeginScroll:` is not a delegate method.
Instead I do
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldHide" object:self];
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate
{
if(!decelerate)
[[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide"
object:self];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide"
object:self];
}
Anywhere in the app objects can listen for this notification,like
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldHide"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
//hide tab bar with animation;
}];
[[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldUnhide"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
//Unhide tab bar with animation;
}];
}
This code will hide the bars for any scroll. if you want to have only on down, the same `locationOffset` trick as in the accepted answer should work.
Problem
I would like to hide both bars on scroll down on my iPhone. When I scroll up, they should appear again.. How can I handle this?