0

I want to show view on the top of the tableview when scroll down and hide when scroll up.

Here is my effort

tblView.tableHeaderView=headerToolbar;
[tblView setContentOffset:CGPointMake(0, 44) animated:YES];

When User Scroll

 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {

    CGPoint targetPoint = *targetContentOffset;
    CGPoint currentPoint = scrollView.contentOffset;

    if (targetPoint.y > currentPoint.y) {
        [tblView setContentOffset:CGPointMake(0, 0) animated:NO];
    }
    else {
        [tblView setContentOffset:CGPointMake(0, 44) animated:NO];
    }
}

But its not working when scroll up.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
  • Does *targetContentOffset dereference to a CGPoint? That looks strange. Are you trying to implement a pull-down-to-refresh function? iOS supplies one now, called UIRefreshControl. https://developer.apple.com/library/ios/documentation/uikit/reference/UIRefreshControl_class/Reference/Reference.html – danh Feb 23 '14 at 06:17
  • yes not exactly but i have view when user scroll down it will be visible other then it will behind the navigaton bar and when scroll down it will visible and down it will go behind the navigation bar – Sunny Shah Feb 23 '14 at 06:33
  • Simply find the scrolling direction(see my answer). Add you header view on top of table view. If you want animation for header view to slide under navigation bar,instead of show/hide, animate the rect of your view on Y-axis. Say your view height is 44, when you want to show it animate Y to 0 and while hiding animate Y to -44. – dev gr Feb 23 '14 at 07:34
  • @devgr dost i m not getting you i dont want to addsubview on the top of the navigation bar. if i do this i will not get effect like in tableview – Sunny Shah Feb 23 '14 at 07:56
  • @Sunnyshah dont add anything on navigation bar, add it root view of your controller containing table view. Determine scroll direction(up/down) of table view and animate the view to get the desired effect. – dev gr Feb 23 '14 at 10:40

2 Answers2

0

Instead of playing with header view, I would suggest add your header view as subview on top of UITableView with desired rect. When user scroll up/down show/hide the your header view on top of table view. You can find scrolling direction of UITableView using this.

Community
  • 1
  • 1
dev gr
  • 2,409
  • 1
  • 21
  • 33
0

Add a UIView on top of the UITableView. That helps you to hide & show your view.

Just update with this.

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {

    CGPoint targetPoint = *targetContentOffset;

    CGPoint currentPoint = scrollView.contentOffset;

    if (targetPoint.y > currentPoint.y) {

        [self.view insertSubview:theTableView aboveSubview:yourView];
    }

    else {

        [self.view insertSubview:yourView aboveSubview:theTableView];
    }

}
Jordan Montel
  • 8,227
  • 2
  • 35
  • 40
Nikunj
  • 280
  • 3
  • 15