Adrian
Adrian

Reputation: 20068

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

I have an UILabel 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 setContentOffset 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 ?

Upvotes: 1

Views: 431

Answers (1)

Josh Homann
Josh Homann

Reputation: 16327

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.

Upvotes: 2

Related Questions