獲取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();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM