i need help, i am trying to build a app in which i have a viewcontroller
with a uiwebview
and a navbar
with 2 buttons on it. what i want to do is that when user scroll uiwebview
navbar automatically hides like slid up sort of. but is not working they way i want it to work. let me post code here.
In viewdidload
i put this.
[webPage.scrollView setDelegate:self];
and then i have this method
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
if(scrollView.contentOffset.y == 0) {
//show
NSLog(@"Show");
[self.navigationController setNavigationBarHidden:NO animated:YES];
} else {
NSLog(@"Hide");
[self.navigationController setNavigationBarHidden:YES animated:YES];
//hide
}
}
it NSLog
correctly but nothing else navbar
still stays. :(
Easy as add this on the ViewController implementation file (.m):
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView.scrollView.delegate = self;
}
#pragma mark - UIScrollViewDelegate Methods
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.lastOffsetY = scrollView.contentOffset.y;
}
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
bool hide = (scrollView.contentOffset.y > self.lastOffsetY);
[[self navigationController] setNavigationBarHidden:hide animated:YES];
}
AND don't forget to add UIScrollViewDelegate
protocol in the header file (.h) :
@interface MyViewController : UIViewController <UIScrollViewDelegate>
...
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With