CCTextFieldTTF输入框

class HelloWorld : public cocos2d::CCLayer, cocos2d::CCTextFieldDelegate//实现代理

{

public:

    //.......//

//重写回调函数

//启动键盘

    virtual bool onTextFieldAttachWithIME(cocos2d::CCTextFieldTTF * sender);

       

//关闭键盘 

    virtual bool onTextFieldDetachWithIME(cocos2d::CCTextFieldTTF * sender);

       

//输入时  

    virtual bool onTextFieldInsertText(cocos2d::CCTextFieldTTF * sender, const char * text, int nLen);

//删除时   

    virtual bool onTextFieldDeleteBackward(cocos2d::CCTextFieldTTF * sender, const char * delText, int nLen);


    

};


#endif 


//创建对象

 CCTextFieldTTF *textField = CCTextFieldTTF::textFieldWithPlaceHolder("请输入。。", "Arial", 18);

    textField->setPosition(ccp(size.width*0.5,size.height*0.7));

    textField->setDelegate(this);

    textField->attachWithIME();//开启输入

    this->addChild(textField);


//实现代理方法

bool HelloWorld::onTextFieldAttachWithIME(CCTextFieldTTF * sender)

{

    CCLog("启动输入。。");

    return false;

}


bool HelloWorld::onTextFieldDetachWithIME(CCTextFieldTTF * sender)

{

    CCLog("关闭输入");

    return false;

}


bool HelloWorld::onTextFieldInsertText(CCTextFieldTTF * sender, const char * text, int nLen)

{

    CCLog("输入字符");

    return false;

}


bool HelloWorld::onTextFieldDeleteBackward(CCTextFieldTTF * sender, const char * delText, int nLen)

{

    CCLog("删除字符");

    return false;

}






你可能感兴趣的:(CCTextFieldTTF输入框)