How to enable or disable scrolling in a UITableView?

I know about this command:

self.tableView.scrollEnabled = true 

The question is, I want to block the scroll according to the scrollView position. For this, I:

 let topEdge = scrollView.contentOffset.y let followersViewEdge = CGRectGetHeight(self.profileView.frame) - 50 if topEdge >= followersViewEdge { self.tableView.scrollEnabled = true } 

it works, but the problem is that it does not lock and does not unlock scrolling immediately. To lock or unlock the UITableView scroll, I need to lift my finger from the screen and scroll again. In this case, it works.

I want to do this immediately, so it locks and unlocks the scroll while I view the screen. How can i do this?

UPDATE

My code is working. It's not a problem. The problem is that I need to make these changes immediately, without releasing my finger from the screen.

So don't tell me how to block scrolling! I know how to do this.

+5
source share
3 answers
  • Choose a table view
  • select attribute inspector
  • In the scroll view section, clear the Enable scroll property check box.
+1
source

You need to configure the gesture recognizer to view the table and listen to the listener.

You can block it with an approach.

  if topEdge >= followersViewEdge { self.tableView.scrollEnabled = true } 

Using the gesture recognizer, you can lock / unlock it.

  if(self.tableView.scrollEnabled) { self.tableView.scrollEnabled = false } else { self.tableView.scrollEnabled = true } 

Example

  // Added the Pan Recognizer for capture the touches UIPanGestureRecognizer *panReconizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panReconizer:)]; panReconizer.maximumNumberOfTouches = panReconizer.minimumNumberOfTouches = 1; [self.tableView addGestureRecognizer:panReconizer]; - (void)panReconizer:(UIPanGestureRecognizer *)pan { NSLog(@" .............. pan detected!! ..................."); if(self.tableView.scrollEnabled) { self.tableView.scrollEnabled = false } else { self.tableView.scrollEnabled = true } } 
0
source

Set contentOffset to maximum when scrolling:

 let topEdge = scrollView.contentOffset.y let followersViewEdge = CGRectGetHeight(self.profileView.frame) - 50 if topEdge >= followersViewEdge { self.tableView.contentOffset.y = followersViewEdge } 
0
source

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


All Articles