UIScrollView, reaching the bottom of the scroll view

后端 未结 7 1619
暗喜
暗喜 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 16:55

    So if you want it in swift, here you go:

    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    
        if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
            //reach bottom
        }
    
        if (scrollView.contentOffset.y < 0){
            //reach top
        }
    
        if (scrollView.contentOffset.y >= 0 && scrollView.contentOffset.y < (scrollView.contentSize.height - scrollView.frame.size.height)){
            //not top and not bottom
        }
    }
    

提交回复
热议问题