获取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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值