美文网首页
上滑加载数据

上滑加载数据

作者: 冢虎_779e | 来源:发表于2019-12-13 10:47 被阅读0次

上滑加载数据


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()

        }

    }

相关文章

网友评论

      本文标题:上滑加载数据

      本文链接:https://www.haomeiwen.com/subject/eoqfnctx.html