cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.12k stars 7.05k forks source link

含有Btn的RichText 放到Listview里 Btn无法触发点击事件 #14251

Closed 1078559858 closed 8 years ago

1078559858 commented 8 years ago

现在的用法是 开发聊天 使用的是 ListView 里面 添加 RichText richText 里面自定义了一个按钮 这个按钮接受不到 点击事件

我在DEMO 里面 做的个例子 如果没有放到 LIstView 的时候 RichText里面的Button 是 可以点击的, 然而 我把RichText 放到listview 里面 按钮 不可点击 我在 coco2d-x 3.6 3.7 3.8 都测试过 能不能 listview 里面的RichText 里面的 Button 能接收到点击事件啊 多谢 多谢 ;)

下面是例子代码 self._richText = ccui.RichText:create() self._richText:ignoreContentAdaptWithSize(false) self._richText:setContentSize(cc.size(200, 100))

local re1 = ccui.RichElementText:create(1, cc.c3b(255, 255, 255), 255, "This color is white. ", "Helvetica", 10)
local re2 = ccui.RichElementText:create(2, cc.c3b(255, 255,   0), 255, "And this is yellow. ", "Helvetica", 10)
local re3 = ccui.RichElementText:create(3, cc.c3b(0,   0, 255), 255, "This one is blue. ", "Helvetica", 10)
local re4 = ccui.RichElementText:create(4, cc.c3b(0, 255,   0), 255, "And green. ", "Helvetica", 10)
local re5 = ccui.RichElementText:create(5, cc.c3b(255,  0,   0), 255, "Last one is red ", "Helvetica", 10)

local reimg = ccui.RichElementImage:create(6, cc.c3b(255, 255, 255), 255, "cocosui/sliderballnormal.png")

ccs.ArmatureDataManager:getInstance():addArmatureFileInfo("cocosui/100/100.ExportJson")
local arr = ccs.Armature:create("100")
arr:getAnimation():play("Animation1")

local recustom = ccui.RichElementCustomNode:create(1, cc.c3b(255, 255, 255), 255, arr)

local function touchEvent(sender, eventType)
    print("eventType", eventType)
end
local button = ccui.Button:create()
button:setTouchEnabled(true)
button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "")
button:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))
button:addTouchEventListener(touchEvent)

local recustom1 = ccui.RichElementCustomNode:create(1, cc.c3b(255, 255, 255), 255, button)
local re6 = ccui.RichElementText:create(7, cc.c3b(255, 127,   0), 255, "Have fun!! ", "Helvetica", 10)
self._richText:pushBackElement(re1)
self._richText:insertElement(re2, 1)
self._richText:pushBackElement(re3)
self._richText:pushBackElement(re4)
self._richText:pushBackElement(re5)
self._richText:insertElement(reimg, 2)
self._richText:pushBackElement(recustom)
self._richText:pushBackElement(recustom1)
self._richText:pushBackElement(re6)

self._richText:setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2))
self._richText:setLocalZOrder(10)

print("richText:getVirtualRendererSize()1=================")
print(self._richText:getContentSize().width, self._richText:getContentSize().height)

self._richText:formatText()
print("richText:getVirtualRendererSize2=================")
print(self._richText:getContentSize().width, self._richText:getContentSize().height)

local listView = ccui.ListView:create()
-- set list view ex direction
listView:setDirection(ccui.ScrollViewDir.vertical)
listView:setBounceEnabled(true)
listView:setBackGroundImage("cocosui/green_edit.png")
listView:setBackGroundImageScale9Enabled(true)
listView:setContentSize(cc.size(240, 130))
listView:setPosition(cc.p(100, 100))

listView:addChild(self._richText)

self:addChild(listView)

11

12

zilongshanren commented 8 years ago

@1078559858 the current implementation of RichText is badly designed and we don't have any plan to continue improving it. We are planning to rewrite the RichText.