上滑加载数据

上滑加载数据


overridefuncscrollViewDidScroll(_scrollView:UIScrollView) {

        letoffset = scrollView.contentOffset

        letbounds = scrollView.bounds

        letsize = scrollView.contentSize

        letinset = scrollView.contentInset

        letscrollViewHeight = bounds.size.height

        letcurrentOffset = offset.y+scrollViewHeight-inset.bottom

        letmaximumOffset = size.height



        letminSpace:CGFloat=5

        letmaxSpace:CGFloat=10

        varisNeedLoadMore =false

        //上拉加载更多

        //tableview 的 content的高度 小于 tableview的高度

        ifscrollViewHeight >= maximumOffset {

            letspace = currentOffset-scrollViewHeight

            ifspace > minSpace&&space < maxSpace {

                isNeedLoadMore =true

            }

        }else{

            //当currentOffset与maximumOffset的值相差很小时,说明scrollview已经滑到底部了。

            letspace = currentOffset-maximumOffset

            ifspace > minSpace&&space < maxSpace {

                isNeedLoadMore =true

            }

        }



        if  isLoading&&isNeedLoadMore {

            isLoading=true

            print("-->加载更多数据")

            self.familyViewModel.returnData {

                self.familyViewModel.startAt += 10

                self.tableView.reloadData()

            }

//            self.loadMore()

        }

    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容