cocos版本3.15,使用studio编辑界面
-- 创建item
local item1 =Item:create(array[index])
item1:setPosition(pos)self.ui.listview:addChild(item1)
item是studio中的搭建的模版,根结点是layout,子节点bg是imageview,其他东西全在imageview下面
我使用的bg作为点击对象,通过下面的方法,我即可以滑动listview,也可以实现item的点击
self.ui.bg:setTouchEnabled(true) -- 设置为可点击
self.ui.bg:setSwallowTouches(false) --设置不吞噬下层触摸
Method.onTouch(self.ui.bg,function ( ... ) -- 点击事件
MUIUtility.playBtnEffect()
print(“-----------onTouch-----------”)
end)
--点击方法
function Method.onTouch(_layer,_callback)
_layer:addTouchEventListener(function(ref, tType)
if tType == ccui.TouchEventType.began then
ref:setColor(cc.c3b(128,128,128))
elseif tType == ccui.TouchEventType.moved then
ref:setColor(cc.c3b(128,128,128))
elseif tType == ccui.TouchEventType.ended then
ref:setColor(cc.c3b(255,255,255))
MUIUtility.playBtnEffect()
_callback()
elseif tType == ccui.TouchEventType.canceled then
ref:setColor(cc.c3b(255,255,255))
end
end)
end