zoukankan      html  css  js  c++  java
  • 获取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();

  • 相关阅读:
    大神总结的
    更改Xcode的缺省公司名
    iPhone分辨率
    iOS 的 APP 如何适应 iPhone 5s/6/6Plus 三种屏幕的尺寸?
    storyBoard(tableViewl)
    storyBoard
    XIB可视化编程
    UITableView(五)
    UITableView(四)
    UITableView(三)
  • 原文地址:https://www.cnblogs.com/mingfuqishi/p/7827267.html
Copyright © 2011-2022 走看看