请问cc.tableview cell添加了ccui.button ,如何让在滚动tableview 时 不会触动ccui.button的点击事件呢?救命啊!!
通过给按钮addTouchEventListener,在ccui.TouchEventType.began事件获取点击开始的Position,然后ccui.TouchEventType.ended事件获取点击结束的Position,比较两个点的位置
– 纵向滑动的tableview
local beginPos = nil
button:addTouchEventListener(function( pBtn, pEvent )
if (pEvent == ccui.TouchEventType.began) then
beginPos = pBtn:getParent():convertToNodeSpace(cc.p(pBtn:getPositionX(), pBtn:getPositionY()))
elseif (pEvent == ccui.TouchEventType.ended) then
local endPos = pBtn:getParent():convertToNodeSpace(cc.p(pBtn:getPositionX(), pBtn:getPositionY()))
if ( pBtn:isVisible() and math.abs(endPos.y - beginPos.y) < pBtn:getContentSize().height * 0.1) then
print(“button click”)
end
end
end)