我用的是cocos2dx2.2版本,textfield的settouchsize 只是一个样式,点击输入框的时候只有点击到文字才能进行输入,当文本长度很短视,体验感差的不行
直接说方法吧,废话也没人看、、
为要点击的区域增加 imageview
exchangeTextBg = dynamic_cast<ImageView *>(ui->getWidgetByName("reward_exchange_bg_0")); exchangeTextBg->setTouchEnabled(true); exchangeTextBg->addTouchEventListener(this,toucheventselector(RewardExchangePanel::onTouchExhcangeTextBg));
这个是textfield
exchangeTextField = dynamic_cast<TextField *>(ui->getWidgetByName("reward_exchange_text"));
头文件
void onTouchExhcangeTextBg(CCObject *target,TouchEventType type);
区域触摸函数,让textfield直接调用attactWithIME()函数就可以了
void RewardExchangePanel::onTouchExhcangeTextBg(CCObject *target,TouchEventType type) { if( type != TouchEventType::TOUCH_EVENT_ENDED) return; exchangeTextField->attachWithIME(); exchangeTextField->setColor(ccc3(70,155,87)); }
以后再也不用纠结输入框点击区域范围太小的问题了,哈哈
时间: 2024-11-04 22:41:19