获取列表当前滑动的百分比

--获取滚动层当前位置的百分比(横向width 纵向height)
function GetScrollViewPercent(scrollView)
if scrollView == nil then return end
local size = scrollView:getInnerContainerSize() --内容区大小
local pos = scrollView:getInnerContainerPosition() --内容区当前位置
local listSize = scrollView:getContentSize() --列表可见区域大小

local persent = 0
--顶部是100,底部是0,所以用100去减 偏移量只移动左下角,所以最大偏移量=总高度 - 列表可见区域
if size.width-listSize.width > 0 then
persent = math.abs(pos.x/(size.width-listSize.width) *100)
end
if pos.x > 0 then
persent = - persent
end
return persent
end

横版的 如果是竖版的话 则把width改成height即可
posted @ 2021-11-25 11:13  习惯了依赖你  阅读(103)  评论(0编辑  收藏  举报