0

I want to be able to show part of the header view of a table when the user pulls down the tableview to make it visible. Similarly, I want to hide it when the user pushes the header out of view.

To do this I have set a content inset to hide the top part of the table. I have also set a content offset to hide the part I want to show

+------------------------------+
| Top part of header (hidden)  |
+------------------------------+
|                              |
| Bottom part (I want to show) |
|                              |
+------------------------------+
|                              |
|                              |
|         Table view           |
|                              |
|                              |
+------------------------------+

The problem is, when I scroll the view, the content offset seems to reset and show the part I wanted to show, even when I push the table up.

This problem is stopping me from using scrollViewWillEndDragging:withVelocity:targetContentOffset:targetContentOffset to animate the content offset relative to the direction I am scrolling.

Here is my code (in viewDidAppear:)

CGRect hiddenPartOfHeaderFrame = self.hiddenPartOfHeaderFrame.frame;

UIEdgeInsets tableContentInset = UIEdgeInsetsMake(- CGRectGetHeight(hiddenPartOfHeaderFrame), 0.0f, 0.0f, 0.0f);

[self.tableView setContentInset:tableContentInset];

CGPoint tableContentOffset = CGPointMake(0.0f, (CGRectGetHeight(self.tableView.tableHeaderView.frame)));

[self.tableView setContentOffset:tableContentOffset];

Is it a property of the content offset to change on scroll, or is there something else going on here I'm not taking in to account?

Thanks as always

Adam Carter
  • 4,741
  • 5
  • 42
  • 103
  • Are you trying to make the table view stick to the visible when the user drags down? In what circumstances do you want the "Bottom part" to be hidden? The `contentOffset` property of a UIScrollView changes when the user scrolls the view (it defines the two dimensional offset within the scroll view — the origin of the sub-rect that you are currently viewing through the scroll view). – simeon Dec 19 '12 at 02:04
  • I think I've sorted it, it seems to be OK so far. I added content to the tableview to see if the problem persists and it doesn't for now. Thanks for the reply though – Adam Carter Dec 19 '12 at 02:22

0 Answers0