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

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

概述http://blog.csdn.net/teng_ontheway/article/details/9162781 【COCOS2DX-游戏开发之八】点击空白隐藏键盘 cocos2dx隐藏键盘点击空白隐藏键盘 cocos2dx edit编辑框点击后显示一个键盘,但是非常的不灵活,点return才能隐藏,如果我们需要点键盘外的背景,实现隐藏键盘,那就方便多了 方法: 1. 到EGLView.mm下

http://blog.csdn.net/teng_ontheway/article/details/9162781


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

cocos2dx隐藏键盘点击空白隐藏键盘

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><span>//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); }




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

[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后d出键盘后无法响应除键盘外的触摸事件解决

参考文章:[iOS] UITextField隐藏软键盘心得(隐藏自身软键盘、点击Return自动转到下个文本框、轻触背景隐藏软键盘)

总结

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

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

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

原文地址: http://outofmemory.cn/web/1045420.html

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

发表评论

登录后才能评论

评论列表(0条)

保存