找不到官方的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();
