--翻页滚动效果
local function fnScrollViewScrolling( sender,eventType)
-- body
if eventType == 10 then
local bposX = sender:getPercentage()*100
_bPosX = bposX
end
if not _bPosX then
return
end
print("-------bposX=",_bPosX)
if ccui.ScrollviewEventType.scrolling == eventType or eventType == 9 then
_IsRolling = true
elseif eventType == 12 then
local edposX = sender:getPercentage()*100
local dispox = edposX - _bPosX
print("--------dispox=",dispox)
if dispox < 0 then
_currPercent = _currPercent - _addPercent
if _currPercent >= 100 then
_currPercent = 100
end
elseif dispox > 0 then
_currPercent = _currPercent + _addPercent
if _currPercent <= 0 then
_currPercent = 0
end
end
sender:scrollToPercentVertical(_currPercent,0.1,false)
print("--------_currPercent=,_addPercent=",_currPercent,_addPercent)
_IsRolling = false
end
end
--绘制商店列表数据
function shopItemList( pBg,tItem )
-- body
require "src/libs/LuaListView"
local itemList = pBg:getChildByTag(999)
if not itemList then
itemList = LuaListView:create()
itemList:setBounceEnabled(true)
itemList:setSize(cc.size(775, 318))
itemList:setPosition(387.5,159+10)--230
itemList:setAnchorPoint(cc.p(0.5,0.5))
itemList:setDirection(ccui.ScrollViewDir.vertical)
itemList:addEventListenerListView(fnScrollViewScrolling)
itemList:setTag(999)
pBg:addChild(itemList)
else
itemList:removeAllItems()
_t_item = {}
end
local point_y = 52
local num = math.ceil(#tItem/2)
local addLayNum = math.mod(num,3)--当不够整页的话根据差别的个数添加空白条目实现上下整体翻页效果
print("-----------------num=,addLayNum=",num,addLayNum)
local layoutSize = cc.size(775,106)
for i=1,num do
local dLayout = ccui.Layout:create()
dLayout:setSize(layoutSize)
if tItem[2*i-1] then
local itemInfo1 = drawShopItemInfo(tItem[2*i -1],2*i -1)
itemInfo1:setPosition(194,point_y) --67
dLayout:addChild(itemInfo1)
end
if tItem[2*i] then
local itemInfo2 = drawShopItemInfo(tItem[2*i],2*i)
itemInfo2:setPosition(582,point_y)
dLayout:addChild(itemInfo2)
end
itemList:pushBackCustomItem(dLayout)
end
if addLayNum ~= 0 then
local disNum = 3- addLayNum
for i=1,disNum do
local dLayout = ccui.Layout:create()
dLayout:setSize(layoutSize)
itemList:pushBackCustomItem(dLayout)
end
end
local height = itemList:getInnerContainer():getContentSize().height-318
print("itemList:getInnerContainer():getContentSize().height=",itemList:getInnerContainer():getContentSize().height)
_addPercent=(318/height)*(-100)
end