Cocos2dx 3.1 、Cocos Studio 1.6 怎么得到ScrollView 滚动的百分比(或者滚动了多少)
这个可以获取内容层的高度来计算,我们正在添加这个功能。
lua代码如下
–获取当前列表百分位
–pnlItems是scrollview
local function getPanelXPercent()
local w = pnlItems:getInnerContainer():getSize().width - 870 --870是你的scrollview 外框大小
return pnlItems:getInnerContainer():getPositionX() / w * (-100)
end
float g=30;
scrollView->scrollToPercentVertical(g,0.0f,false);
float a=scrollView->getInnerContainer()->getSize().height;
float b=scrollView->getInnerContainer()->getPositionY();
g我设成10、20、30都试过了 a和b的值都没变过 b的值不对啊
float g=30;
scrollView->scrollToPercentVertical(g,0.0f,false);
float a=scrollView->getInnerContainer()->getSize().height;
float b=scrollView->getInnerContainer()->getPositionY();
g我设成10、20、30都试过了 a和b的值都没变过 b的值不对啊
顶!!!!!!!
现在这功能加好了没, 加好了的话, 在哪 , 查API好像没看到。
在最新版cocos lua中的获取滚动条位置方法:
scrollview:setInertiaScrollEnabled(true) – 开启滚动条惯性滑动
scrollview:setScrollBarOpacity(0) – 设置滚动条透明度为0 不显示
scrollview:scrollToPercentHorizontal(50,0,false) – 一开始滚动到水平正中间
local scrollWidth = display.width - totalw – totalw=2468 即滚动内容宽度
scrollview:onScroll(function(event)
– if event.name == “SCROLLING” then – end – 该条件开启的话只能检测用户拖动时事件,无法检测惯性滑动事件
local po = event.target:getInnerContainerPosition()
local per = (po.x / scrollWidth) * 100
if per < 0 then per = -per end – per为当前滚动百分比
print(“当前滚动位置:” … po.x … “,” … po.y … " 当前滚动百分比:" … per)
end)