加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 19:17:51 所属栏目:百科 来源:网络整理
导读:cocos2dx edit编辑框点击后显示一个键盘,但是非常的不灵活,点return才能隐藏,如果我们需要点键盘外的背景,实现隐藏键盘,那就方便多了 方法: 1. 到EGLView.mm下 注释2个reurn,这样就能保证显示软键盘的时候,还能将点击事件传送到最底层 [cpp] view pl



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


方法:

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

[cpp] view plain copy
  1. //Passthetouchestothesuperview
  2. #pragmamarkEAGLView-TouchDelegate
  3. -(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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读