How to enable/disable scrolling in UITableView?

随声附和 提交于 2019-12-22 05:16:14

问题


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:


  1. Select tableview
  2. choose Attribute insepector
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!