可以在触摸函数中进行判断是否点击,并弹出键盘
function onTouchBegan(touch ,event)
local isClicked = self ._textField:boundingBox():containsPoint(touch:getLocation())
if (isClicked) then
--弹出软键盘
self._textField:attachWithIME()
end
end
self._textField = ccui.TextField:create("hello easy!","Arial", 36)
self._textField:setPosition(cc.p(500, 300))
self._textField:setMaxLength(240)
self._textField:setMaxLengthEnabled( true)
self._textField:ignoreContentAdaptWithSize( false)-------------关键
self._textField:setContentSize(cc.size(600, 80))---------------关键
self:addChild(self ._textField)
self._textField:setTouchEnabled( true)
也可以直接添加监听函数
textField->addEventListener(textFieldEvent)
local function textFieldEvent(ref, event)