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方法。发现画面不再闪烁。 下班以后。。

。。 汗一个。这个问题从事几乎相同2天,再次感谢google,假如还找不到信息。关于疯狂


暂时还没有发现任何问题。我们欢迎评论!




原文地址:https://www.cnblogs.com/zfyouxi/p/4802558.html