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 (142.9 KB)
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 (142.9 KB)
Thanks. #505 is created for this
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();
thank u for ur solution.
Thank you indeed - I made some changes to CCTextFieldTTF based on your info and it worked like a charm.
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);
}
}
}
Thanks for replying, with the above code, I confirmed that the problem has been fixed on iPad2 ( Simulator ).
But with iPhone 6, iPhone 6 Plus ( iOS 8.4 - Simulator ) when pressing hide button on keyboard, pressing the textfield won’t let the keyboard appear again ( unless press Command + K ) which is weird since I think there no such shortcut on real device, could any one confirming with real device please ? Thanks for reading.
Noted : With these code above, iPhone 6 ( iOS 8.4 Simulator ) could only fire the TextField::EventType::DETACH_WITH_IME and the “canDetachWithIME()” function always return true regardless of pressing return or “Hide keyboard” on the iPhone 6’s soft keyboard, unlike it was like on the iPad 2 Siumlator, is it me or the simulator or device problem ? Thanks again.