标签:
文本框控件CCTextFieldTTF:
const char* getString(void); 获取当前字符串 bool attachWithIME(); 激活输入法 bool detachWithIME(); 取消激活输入法
1 CCTextFieldTF text = CCTextFieldTTF::textFieldWithPlaceHodler("Input Your name...", "Arial", 20); 2 text->setPosition(ccp(winSize.width/2, winSize.height/2 + 40)); 3 this->addChild(text); 4 text->attachWithIME();
1 CCMenuItem* tapItem = CCMenuItemFont::create(" ", this, menu_selector(StartScene::textFiledPressed)); 2 tapItem->setPosition(cp(winSize.width/2, winSize.height/2 + 40)); 3 menu->addChild(tapItem, 1); 4 //并且将显示输入法放到响应函数中 5 void StartScene::textFieldPressed(cocos2d::CCObject *sender) 6 { 7 text->attachWithIME(); 8 }
virtual bool onTextFeildAttachWithIME(CCTextFieldTTF *sender);
virtual bool onTextFieldDetachWithIME(CCTextFieldTTF *sender);
virtual bool onTextFieldInsertText(CCTextFieldTTF *sender, const char * text, int nLen);
virtual bool onTextFieldDeleteBackward(CCTextFieldTTF *sender, const char *delText, int nLen);
virtual bool onDraw(CCTextFieldTTF *sender);
1 bool StartScene::onTextFieldAttachWithIME(cocos2d::CCTextFieldTTF *sender) 2 { 3 this->setPosition(ccp(0, 100)); 4 return false; 5 } 6 bool StartScene::onTextFieldDetachWithIME(cocos2d::CCTextFieldTTF *sender) 7 { 8 this->setPosition(ccp(0, 0)); 9 return false; 10 } 11 //最后,设置文本框和协议响应方 12 text->setDelegate(this);
标签:
原文地址:http://www.cnblogs.com/Blogs-young-chan/p/5223488.html