keyboard splitting bug on ipad with ios 5 and 6 (Cocos2d-x)

Had the same issue - the solution is to stop the opengl layer from rendering while this is happening. Here’s what I did:

1) Register for keyboard frame change events at start of application. I did this in AppController.mm

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...

[[NSNotificationCenterdefaultCenter] addObserver:self

                                       selector:@selector(keyboardWillChangeFrame:)

                                       name:UIKeyboardWillChangeFrameNotification

                                              object:nil];//UIKeyboardWillChangeFrameNotification

[[NSNotificationCenterdefaultCenter] addObserver:self

                                            selector:@selector(keyboardDidChangeFrame:)

                                                name:UIKeyboardDidChangeFrameNotification

                                              object:nil];



...
}

2) Started and stopped rendering during keyboard animation.

-(void)keyboardWillChangeFrame:(NSNotification *)notification {

    NSLog(@"keyboardWillChangeFrame");

    // stop openGL animation while animating keyboard

    cocos2d::CCDirector::sharedDirector()->stopAnimation();

}

-(void)keyboardDidChangeFrame:(NSNotification *)notification {// restart openGL animation when keyboard stops animating

    cocos2d::CCDirector::sharedDirector()->startAnimation();

}


上面是从google上搜出来的答案,百度找了很久没找到答案。 :《  google经常不好用。。。

okay,到目前为止,键盘分拆,浮动,收回动作可以完美展现。但是出现了一点瑕疵,键盘收起时,会出现输入框中的字有闪烁,以挑剔的眼光来说,这是个问题:

看上面代码,在键盘出现变化时,停止所有的动画,键盘结束时继续,debug后发现就是在动画停止的时候文字消失,开始动画后出现。判断是因为控件儿在停止编辑事件/键盘收起事件中有重新设置文字信息。

经过查找:在CCEditBoxImplIOS.mm中发现了---

- (BOOL)textFieldShouldEndEditing:(UITextField *)sender

{

    CCLOG("textFieldShouldEndEditing...");

    editState_ = NO;

    getEditBoxImplIOS()->setText(getEditBoxImplIOS()->getText());

    

    cocos2d::extension::CCEditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate();

    if (pDelegate != NULL)

    {

        pDelegate->editBoxEditingDidEnd(getEditBoxImplIOS()->getCCEditBox());

        pDelegate->editBoxReturn(getEditBoxImplIOS()->getCCEditBox());

    }

    

    cocos2d::extension::CCEditBox*  pEditBox= getEditBoxImplIOS()->getCCEditBox();

    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())

    {

        cocos2d::CCScriptEngineProtocol* pEngine = cocos2d::CCScriptEngineManager::sharedManager()->getScriptEngine();

        pEngine->executeEvent(pEditBox->getScriptEditBoxHandler(), "ended",pEditBox);

        pEngine->executeEvent(pEditBox->getScriptEditBoxHandler(), "return",pEditBox);

    }

if(editBox_ != nil)

{

// getEditBoxImplIOS()->onEndEditing(); //就是这里,onEndEditing重新给设置内容了,似乎内容没有任何的变化

}

    return YES;

}


void CCEditBoxImplIOS::onEndEditing()

{

m_systemControl.textField.hidden = YES;

if(strlen(getText()) == 0)

{

m_pLabel->setVisible(false);

m_pLabelPlaceHolder->setVisible(true);

}

else

{

m_pLabel->setVisible(true);

m_pLabelPlaceHolder->setVisible(false);

setInactiveText(getText());

}

}


注释掉 textFieldShouldEndEditing方法后,发现闪烁消失了。 工作完成。。。。 汗一个,这个问题搞了差不多两天,再次感谢google,如果还不能找到信息,就该发狂了


暂时还没有发现有什么问题,欢迎大家提意见!




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值