采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果相关的知识,希望对你有一定的参考价值。
--翻页滚动效果
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
以上是关于采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果的主要内容,如果未能解决你的问题,请参考以下文章
如何解决failed to push some refs to git
如何解决failed to push some refs to git
Cocos2d 2.x:我似乎无法更改 3GS 的启动图像!它仍然显示 Cocos2d 橙色默认图像