【COCOS2DX-游戏开发之八】点击空白隐藏键盘

【COCOS2DX-游戏开发之八】点击空白隐藏键盘,第1张

概述cocos2dx edit编辑框点击后显示一个键盘,但是非常的不灵活,点return才能隐藏,如果我们需要点键盘外的背景,实现隐藏键盘,那就方便多了 方法: 1. 到EGLView.mm下 注释2个reurn,这样就能保证显示软键盘的时候,还能将点击事件传送到最底层 [cpp]  view plain copy // Pass the touches to the superview   #pra



cocos2dx edit编辑框点击后显示一个键盘,但是非常的不灵活,点return才能隐藏,如果我们需要点键盘外的背景,实现隐藏键盘,那就方便多了


方法:

1. 到EGLVIEw.mm下 注释2个reurn,这样就能保证显示软键盘的时候,还能将点击事件传送到最底层

[cpp] view plain copy //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); }
copy -(voID)touchesEnded:(NSSet*)toucheswithEvent:(UIEvent*)event <strong><spanstyle="color:#ff0000;">//WARNING:commentedbyTeng.点触背景隐藏软键盘</span> //return;</strong> cocos2d::CCEGLVIEw::sharedOpenGLVIEw()->handletouchesEnd(i,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> }


2.最底层的layer类中添加处理:显示和隐藏键盘就OK了

copy voID
cctouchended(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(); }
转载自:http://blog.csdn.net/teng_ontheway/article/details/9162781 总结

以上是内存溢出为你收集整理的【COCOS2DX-游戏开发之八】点击空白隐藏键盘全部内容,希望文章能够帮你解决【COCOS2DX-游戏开发之八】点击空白隐藏键盘所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1007296.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存