Currently I have a UICollection
in which I hide the UINavigation
Top Bar when you scroll down 40px. The UINavigation
Top Bar appears again when you scroll back up to the top.
This works however I want to be able to show /hide the UINavigation
Top Bar anytime the user scrolls 40px and not only when you scroll from the top.
e.g When you start scrolling from the top the bar hides, You scroll to the middle of the UICollectionView and then when you strat scrolling back to the top the UINavigation
Top Bar shows again.
Any ideas?
#pragma mark - UIScrollViewDelegate Methods
-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0f){
return;
}
CGRect frame = self.navigationController.navigationBar.frame;
frame.origin.y = 20;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0f){
return;
}
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat contentHeight = scrollView.contentSize.height - 300;
if (offsetY > contentHeight - scrollView.frame.size.height)
{
[self.homePaginator fetchNextPage];
}
CGRect frame = self.navigationController.navigationBar.frame;
CGFloat size = frame.size.height - 25;
if([scrollView.panGestureRecognizer translationInView:self.view].y < 0)
{
frame.origin.y = -size;
if(self.navigationController.navigationBar.items.count > 0){
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
CGFloat navBarHeight = 25.0f;
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, navBarHeight);
[self.navigationController.navigationBar setFrame:frame];
}
completion:^(BOOL finished) {
self.navigationItem.titleView.alpha = 0;
self.piccingTitleIcon.alpha = 0;
self.navigationItem.rightBarButtonItem = nil;
}];
}
}
else if([scrollView.panGestureRecognizer translationInView:self.view].y > 0)
{
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
CGFloat navBarHeight = 64.0f;
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, navBarHeight);
[self.navigationController.navigationBar setFrame:frame];
self.navigationItem.titleView.alpha = 1;
self.piccingTitleIcon.alpha = 1;
self.btnSearch = [[UIBarButtonItem alloc] initWithCustomView:self.searchIconButton];
[self.navigationItem setRightBarButtonItem:self.btnSearch];
}
completion:^(BOOL finished) {
[self performSelector:@selector(addIconsToNavBar) withObject:nil afterDelay:-1.0];
}];
}
}