问题
I know about this command:
self.tableView.scrollEnabled = true
The question is: I want to lock scrolling according to the scrollView position. For this I do:
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 or unlock the scrolling immediately. For locking or unlocking the UITableView scrolling I need to release my finger from the screen and scroll again. In this case it works.
I want to make it immediately, so it locks and unlocks the scrolling while I'm swiping on the screen. How can I do it?
UPDATE
My code works. It's not a problem. Problem is that I need to make these changes immediately, without releasing my finger from the screen.
So, do not answer me how to lock scrolling! I know how to do this.
回答1:
- Select tableview
- choose Attribute insepector
- In scroll view section, uncheck Scrolling Enabled property
回答2:
Force the contentOffset
to your max value while scrolling :
let topEdge = scrollView.contentOffset.y
let followersViewEdge = CGRectGetHeight(self.profileView.frame) - 50
if topEdge >= followersViewEdge {
self.tableView.contentOffset.y = followersViewEdge
}
回答3:
You need to setting up the pan gesture recognizer for your table view and keep listening listener.
By you approach can lock it.
if topEdge >= followersViewEdge {
self.tableView.scrollEnabled = true
}
By the pan 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
}
}
来源:https://stackoverflow.com/questions/35721849/how-to-enable-disable-scrolling-in-uitableview