UIScrollView, reaching the bottom of the scroll view

后端 未结 7 1604
暗喜
暗喜 2020-12-07 16:05

I know the Apple documentation has the following delegate method:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      // called when scroll         


        
相关标签:
7条回答
  • 2020-12-07 17:04

    Actually, rather than just putting @bensnider's code in scrollViewDidScroll, this code (written in Swift 3) would be better performance-wise:

    func scrollViewDidEndDragging(_ scrollView: UIScrollView,
                                  willDecelerate decelerate: Bool) {
        if !decelerate {
            checkHasScrolledToBottom()
        }
    }
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        checkHasScrolledToBottom()
    }
    
    func checkHasScrolledToBottom() {
        let bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height
        if bottomEdge >= scrollView.contentSize.height {
            // we are at the end
        }
    }
    
    0 讨论(0)
提交回复
热议问题