http://blog.csdn.net/teng_ontheway/article/details/9162781
cocos2dx edit编辑框点击后显示一个键盘,但是非常的不灵活,点return才能隐藏,如果我们需要点键盘外的背景,实现隐藏键盘,那就方便多了
方法:
1. 到EGLView.mm下 注释2个reurn,这样就能保证显示软键盘的时候,还能将点击事件传送到最底层
[cpp] view plaincopy
- //Passthetouchestothesuperview
- #pragmamarkEAGLView-TouchDelegate
- -(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event
- {
- if(isKeyboardShown_)
- {
- [selfhandleTouchesAfterKeyboardShow];
- //WARNING:commentedbyTeng.点触背景隐藏软键盘
- //return;
- }
- intids[IOS_MAX_TOUCHES_COUNT]={0};
- floatxs[IOS_MAX_TOUCHES_COUNT]={0.0f};
- floatys[IOS_MAX_TOUCHES_COUNT]={0.0f};
- inti=0;
- for(UITouch*touchintouches){
- ids[i]=(int)touch;
- xs[i]=[touchlocationInView:[touchview]].x*view.contentScaleFactor;;
- ys[i]=[touchlocationInView:[touchview]].y*view.contentScaleFactor;;
- ++i;
- }
- cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesBegin(i,ids,xs,ys);
- }
[cpp] view plaincopy
- -(void)touchesEnded:(NSSet*)toucheswithEvent:(UIEvent*)event
- {
- if(isKeyboardShown_)
- {
- <strong><spanstyle="color:#ff0000;">//WARNING:commentedbyTeng.点触背景隐藏软键盘</span>
- //return;</strong>
- }
- intids[IOS_MAX_TOUCHES_COUNT]={0};
- floatxs[IOS_MAX_TOUCHES_COUNT]={0.0f};
- floatys[IOS_MAX_TOUCHES_COUNT]={0.0f};
- inti=0;
- for(UITouch*touchintouches){
- ids[i]=(int)touch;
- xs[i]=[touchlocationInView:[touchview]].x*view.contentScaleFactor;;
- ys[i]=[touchlocationInView:[touchview]].y*view.contentScaleFactor;;
- ++i;
- }
- cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesEnd(i,ys);
- }
[cpp] view plaincopy
- voidccTouchEnded(cocos2d::CCTouch*pTouch,cocos2d::CCEvent*pEvent)
- {
- do
- {
- if(mTelNumber){
- CCPointendPos=pTouch->getLocation();
- floatdelta=5.f;
- if(::abs(mBeginPos.x-endPos.x)>delta
- ||::abs(mBeginPos.y-endPos.y)>delta){
- break;
- }
- //看编辑框是否被点中
- CCPointpoint=mTelNumber->getParent()->convertTouchToNodeSpaceAR(pTouch);
- //锚点(0.f,0.5f)
- //intx=mTextField->getParent()->getPosition().x;
- //inty=mTextField->getParent()->getPosition().y;
- intw=mTelNumber->getContentSize().width;
- inth=mTelNumber->getContentSize().height;
- CCRectrect=CCRect(0,-h/2,w,h);
- onClickedTextField(rect.containsPoint(point));
- }
- }while(0);
- DialogLayer::ccTouchEnded(pTouch,pEvent);
- }
- /**点击推广码输入框*/
- voidonClickedTextField(boolb)
- {
- if(b){
- mTelNumber->attachWithIME();
- }else{
- mTelNumber->detachWithIME();
- }
- }
参考文章:Cocos2d-x游戏开发之2.x后弹出键盘后无法响应除键盘外的触摸事件解决
参考文章:[iOS] UITextField隐藏软键盘心得(隐藏自身软键盘、点击Return自动转到下个文本框、轻触背景隐藏软键盘)
原文链接:https://www.f2er.com/cocos2dx/344127.html