local scroll_view = CCScrollView:create()
local view_width = 405
local view_height = 231
scroll_view:setViewSize(CCSizeMake(view_width,view_height))
scroll_view:setDirection(1) – 方向
local containerLayer = CCLayer:create()
scroll_view:setContainer(containerLayer)
self:addChild(scroll_view)
local h =0
for i=1,30 do
local item = display.newSprite(“UICommon/hero_item_nor.png”) – 405*77
item:setAnchorPoint(ccp(0,0))
local text = string.format(“hello,world%s”,h/77)
local label = CCLabelTTF:create(text,"",20,CCSize(0,0),1)
label:setPosition(200,40)
item:addChild(label)
item:setPosition(0,h)
h = 77*i
containerLayer:addChild(item)
end
local function onTouch(evt,x,y)
printInfo("-给我打印出来啊,亲,不到到–evt:%s,(x:%s,y:%s)",evt,x,y)
end
scroll_view:setContentOffset(ccp(0,view_height-h))
scroll_view:setPosition(120,100)
scroll_view:setContentSize(CCSizeMake(view_width,h))
containerLayer:registerScriptTouchHandler(onTouch,false,-128)
–container_layer:addNodeEventListener(cc.NODE_TOUCH_EVENT,PanelOnTouch )
containerLayer:setTouchEnabled(true)
containerLayer:setTouchSwallowEnabled(false)
1:点击前面的ITEM 不会有touch事件,但是拉到比较后的时候就会有。
感谢廖大!和 quick团队