h5nc Thor Text input cannot call onTextFieldDetachWithIME on iPad when click "hide" on soft keyboard
Posts 10
Added by h5nc Thor about 2 years ago

Not sure if it is a bug since the soft key is designed for hiding the keyboard. Only iPad has that key on its soft keyboard, different from return key, which is handled automatically.

未标题-1.jpg - the one on the right bottom corner (139.6 kB)

Zhe Wang RE: Text input cannot call onTextFieldDetachWithIME on iPad when click "hide" on soft keyboard
Posts 1642
Location Amoy, China
Added by Zhe Wang about 2 years ago

Thanks. #505 is created for this

Enjoy Coding, Enjoy Life.

Emmanuel B. RE: Text input cannot call onTextFieldDetachWithIME on iPad when click "hide" on soft keyboard
Posts 77
Added by Emmanuel B. over 1 year ago

It's been quite a while so I am guessing that it is intended behavior.

I ran across this small issue and would like to share with the community how to handle this situation. Inherit from CCIMEDelegate and override: void keyboardDidHide(cocos2d::CCIMEKeyboardNotificationInfo& info);

From there you can manually detach the IME: inputField->detachWithIME();

小 苏 RE: Text input cannot call onTextFieldDetachWithIME on iPad when click "hide" on soft keyboard
Posts 83
Added by 小 苏 over 1 year ago

thank u for ur solution.

Loic Argelies RE: Text input cannot call onTextFieldDetachWithIME on iPad when click "hide" on soft keyboard
Posts 6
Added by Loic Argelies about 1 year ago

Thank you indeed - I made some changes to CCTextFieldTTF based on your info and it worked like a charm.

Loic Argelies RE: Text input cannot call onTextFieldDetachWithIME on iPad when click "hide" on soft keyboard
Posts 6
Added by Loic Argelies about 1 year ago

here are the code changes.

in CCTextFieldTTF.h

class CC_DLL CCTextFieldDelegate
{
public:

    [...]

    virtual bool onDraw(CCTextFieldTTF * sender)
    {
        CC_UNUSED_PARAM(sender);
        return false;
    }

    //line additions
    virtual void    onTextFieldDidAttachIME( CCTextFieldTTF * sender ) {  CC_UNUSED_PARAM(sender); } // added this to deal with iPad hide key - line addition
    virtual void    onTextFieldDidDetachIME( CCTextFieldTTF * sender ) {  CC_UNUSED_PARAM(sender); } // added this to deal with iPad hide key - line addition
};

class CC_DLL CCTextFieldTTF : public CCLabelTTF, public CCIMEDelegate
{
public:
    CCTextFieldTTF();
    virtual ~CCTextFieldTTF();

    [...]

    // cocos2d-x fix (addition)
    void keyboardDidHide(cocos2d::CCIMEKeyboardNotificationInfo& info);                     // needed to handle iPad soft keyboard "hide" key - line addition

    //////////////////////////////////////////////////////////////////////////
    // properties
    //////////////////////////////////////////////////////////////////////////

in CCTextFieldTTF.cpp

bool CCTextFieldTTF::attachWithIME()
{
    bool bRet = CCIMEDelegate::attachWithIME();
    if (bRet)
    {
        // open keyboard
        CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();
        if (pGlView)
        {
            pGlView->setIMEKeyboardState(true);
            if ( m_pDelegate ) m_pDelegate->onTextFieldDidAttachIME( this ) ; // line addition
        }
    }
    return bRet;
}

bool CCTextFieldTTF::detachWithIME()
{
    bool bRet = CCIMEDelegate::detachWithIME();
    if (bRet)
    {
        // close keyboard
        CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();
        if (pGlView)
        {
            pGlView->setIMEKeyboardState(false);
            if ( m_pDelegate ) m_pDelegate->onTextFieldDidDetachIME( this ) ; // line addition
        }
    }
    return bRet;
}

void CCTextFieldTTF::keyboardDidHide(cocos2d::CCIMEKeyboardNotificationInfo& info) // method addition
{
    if ( canDetachWithIME() )  detachWithIME() ;
    else
    {
        // open keyboard
        CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();
        if (pGlView)
        {
            pGlView->setIMEKeyboardState(true);
        }
    }
}

(1-5/5)