Limit Scrolling for a UITableView

I have a TableViewController:

enter image description here

As you can see, I have my own custom panel at the top. The UITable View is just static , and I'm adding a view at the top of the UITableView.

The fact is that when I look at a TableView, it becomes like a sub-image, and I don't want that. Is there any simple code that I can limit to scrolling for a tableView?

enter image description here

+4
source share
5 answers

since UITableView is a subclass of UIScrollView, you can use this UIScrollViewDelegate method to prevent scrolling over the top border

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == self.tableView) { if (scrollView.contentOffset.y < 0) { scrollView.contentOffset = CGPointZero; } } } 
+19
source

Yo will need to set the bounce uitableview property to NO

  UITableView *tableView; tableView.bounces = NO; 

Edit: note that you can also uncheck the boxes from the interface designer

Please check this answer for more details. Disable UITableView vertical bounces when scrolling

+4
source

If I understand correctly, you configured your custom panel as part of your table view. Place your custom bar in a separate view, not in the table view, and when setting up your views, place your table view under the user panel. You need to create your own custom view controller, which will have your custom panel and your static table view.

0
source

You need to create your view controller object as a type of UIViewController , not a UITableViewController . Then add a custom panel as a subtitle in self.view . Create a separate UITableView and add it under the panel. This should do the scrolling of the user pane of static and tabular scrolling.

Update:

To make a static table table static, you need to set it as

 tableView.scrollEnabled = NO: 

Let me know if this works for you.

0
source

I had the same problem and asked our UX-Designer how it would be better to do this. He said that strict decisions (to prevent bouncing, and to allow it as it is) are bad. Better to allow a jump, but only for some space

My solution was:

 override func scrollViewDidScroll(_ scrollView: UIScrollView) { if scrollView == self.tableView { if scrollView.contentOffset.y < -64 { scrollView.scrollRectToVisible(CGRect(origin: CGPoint(x: 0, y: -64), size: scrollView.frame.size), animated: false) scrollView.scrollRectToVisible(CGRect(origin: CGPoint.zero, size: scrollView.frame.size), animated: true) } } } 

Where 64 was for me "some space". The code stops the tableView at -64 from above and displays it using animation. Good luck

0
source

Source: https://habr.com/ru/post/1438719/


All Articles