微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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



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


方法

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

  1. //Passthetouchestothesuperview
  2. #pragmamarkEAGLView-TouchDelegate
  3. -(@H_404_47@void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event
  4. {
  5. if(isKeyboardShown_)
  6. [selfhandletouchesAfterKeyboardShow];
  7. //WARNING:commentedbyTeng.点触背景隐藏软键盘
  8. //return;
  9. }
  10. intids[IOS_MAX_touches_COUNT]={0};
  11. floatxs[IOS_MAX_touches_COUNT]={0.0f};
  12. floatys[IOS_MAX_touches_COUNT]={0.0f};
  13. inti=0;
  14. for(UITouch*touchintouches){
  15. ids[i]=(int)touch;
  16. xs[i]=[touchlocationInView:[touchview]].x*view.contentScaleFactor;;
  17. ys[i]=[touchlocationInView:[touchview]].y*view.contentScaleFactor;;
  18. ++i;
  19. cocos2d::CCEGLView::sharedOpenGLView()->handletouchesBegin(i,ids,xs,ys);
  20. }

copy
    -(void)touchesEnded:(NSSet*)toucheswithEvent:(UIEvent*)event
  1. <strong><spanstyle="color:#ff0000;">//WARNING:commentedbyTeng.点触背景隐藏软键盘</span>
  2. //return;</strong>
  3. 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
    voidccTouchEnded(cocos2d::CCTouch*pTouch,cocos2d::CCEvent*pEvent)
  1. do
  2. if(mTelNumber){
  3. CCPointendPos=pTouch->getLocation();
  4. floatdelta=5.f;
  5. if(::abs(mBeginPos.x-endPos.x)>delta
  6. ||::abs(mBeginPos.y-endPos.y)>delta){
  7. break;
  8. }
  9. //看编辑框是否被点中
  10. CCPointpoint=mTelNumber->getParent()->convertTouchToNodeSpaceAR(pTouch);
  11. //锚点(0.f,0.5f)
  12. //intx=mTextField->getParent()->getPosition().x;
  13. //inty=mTextField->getParent()->getPosition().y;
  14. intw=mTelNumber->getContentSize().width;
  15. inth=mTelNumber->getContentSize().height;
  16. CCRectrect=CCRect(0,-h/2,w,h);
  17. onClickedTextField(rect.containsPoint(point));
  18. }while(0);
  19. DialogLayer::ccTouchEnded(pTouch,pEvent);
  20. /**点击推广码输入框*/
  21. voidonClickedTextField(boolb)
  22. {
  23. if(b){
  24. mTelNumber->attachWithIME();
  25. else{
  26. mTelNumber->detachWithIME();
  27. }

转载自:http://blog.csdn.net/teng_ontheway/article/details/9162781

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐