Kobe Kobe - 11 months ago 79
Swift Question

How to make UITableView header to show only when dragging down table view

I have an

that shows me the current date added to the table view header. When the app is running you can see the header right from the start.

What I am after is when the app starts to not see the header, only when you try to drag the table view down, to reveal the label. And when releasing the header should be hidden again.

I think Snapchat uses this technique in their Stories screen.

Any ideas how can this be achieved ?

I'm thinking something with
when the app starts to move the table view on top of the header. But then how do I do I know when the table view was dragged and released ?

Answer Source

You are correct that you can use setContentOffset to move the tableViewDown. You can implement UIScrollViewDelegate method scrollViewWillEndDragging(:withVelocity:targetContentOffset:) which will tell you when the user lets go of the tableView and then call setContentOffset(:animated:) to animate the tableView back to its initial position.