Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create up/down swipeable UITableView?

I have a UITableView in the bottom of UIViewController and tableview height is 100 point now. storyboard

The tableview has 20 cells and tableview's header view is 100 point. And I've added a up UISwipeGestureRecognizer and a down UISwipeGestureRecognizer in table view header.

Now I want to change the tableview height constraint constant to 400 in up gesture action and change the tableview height constraint constant to 100 in down gesture action.

minimized

maximized

  • Now the problem is gesture recognizer isnt working in tableview header when tableview scroll is enabled.
  • If tableview scroll is disabled then the gesture recognizer is working. But unable to view all cells once the tableview height is changed.
like image 943
RajeshKumar R Avatar asked Jun 11 '26 06:06

RajeshKumar R


1 Answers

Here's a different approach. Don't use swipe gesture recognizers at all.

Instead, make the table always the full 400 points tall. Set its contentInset.top to 300. This will allow the table view to scroll so that only its top 100 points of content are visible at the bottom of the screen. Specifically, the table view will allow its contentOffset.y (which is its vertical scrolling position) to go down to -300 (instead of only down to 0). The table's content always starts at y = 0, so when the table's contentOffset.y is -300, only the top 100 points of its content are visible. As the contentOffset.y increases, more of its content becomes visible.

Then, override the table view's point(inside:withEvent:) method to return true only for points with y >= 0. This means the table will ignore (pass through) touches above its content when its content is scrolled so only the top 100 points are visible.

This is the final effect for a small table:

small table

or for a big table:

big table

You can find a detailed explanation (in Objective-C) and a link to the full test project (also in Objective-C) in this answer.

like image 62
rob mayoff Avatar answered Jun 13 '26 20:06

rob mayoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!