cocos2dx edit编辑框点击后显示一个键盘,但是非常的不灵活,点return才能隐藏,如果我们需要点键盘外的背景,实现隐藏键盘,那就方便多了
方法:
1. 到EGLView.mm下 注释2个reurn,这样就能保证显示软键盘的时候,还能将点击事件传送到最底层
-
- #pragmamarkEAGLView-TouchDelegate
- -(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event
- {
- if(isKeyboardShown_)
- [selfhandleTouchesAfterKeyboardShow];
-
- //WARNING:commentedbyTeng.点触背景隐藏软键盘
-
- }
- 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);
- }
-(void)touchesEnded:(NSSet*)toucheswithEvent:(UIEvent*)event
- <strong><spanstyle="color:#ff0000;">
- //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了
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();
- }
转载自:http://blog.csdn.net/teng_ontheway/article/details/9162781
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|