How Do I Shorten the Pull Distance on UIRefreshControl to Activate the Pull to Refresh Action?

后端 未结 5 1074
傲寒
傲寒 2021-02-07 09:27

Hey StackOverflow People,

I\'ve been trying to figure out this question for some time now but to no avail and I need some help. I have a UITableView close t

5条回答
  •  别跟我提以往
    2021-02-07 09:46

    you can still use refreshControl but with some modifications!

    add these code to your viewController:

    var canRefresh = true
    
    override func scrollViewDidScroll(scrollView: UIScrollView) {
    
        if scrollView.contentOffset.y < -100 { //change 100 to whatever you want
    
            if canRefresh && !self.refreshControl.refreshing {
    
                self.canRefresh = false
                self.refreshControl.beginRefreshing()
    
                self.refresh() // your viewController refresh function
            }
        }else if scrollView.contentOffset.y >= 0 { 
    
            self.canRefresh = true
        }
    }
    

    and as usual in the end of your refresh logic in self.refresh() function add :

       self.refreshControl.endRefreshing()
    

提交回复
热议问题