获取ScrollView ListView的当前位置的百分比

找不到官方的API,就自己写了一下,下面是自己写的函数 

--获取滚动层当前位置的百分比
function GetScrollViewPercent(scrollView)
    if scrollView == nil then return end
    local size = scrollView:getInnerContainerSize()         --内容区大小
    local pos = scrollView:getInnerContainerPosition()      --内容区当前位置
    local listSize = scrollView:getContentSize()            --列表可见区域大小
    
    local persent = 100
    --顶部是100,底部是0,所以用100去减       偏移量只移动左下角,所以最大偏移量=总高度 - 列表可见区域
    if size.height-listSize.height > 0 then
        persent = 100 - math.abs(pos.y/(size.height-listSize.height) *100)
    end

    return persent
end

PS:其他相关,参考来源:http://www.cocoachina.com/bbs/read.php?tid=231462

我是3.9 依次调用一下代码即在本帧让所有items的位置正确。这个是lua (函数是一样的)的,c++的函数有些事protected的要弄成public。
listCtro:requestDoLayout();
listCtro:doLayout();
listCtro:getInnerContainer():forceDoLayout();

原文地址:https://www.cnblogs.com/mingfuqishi/p/7827267.html