zoukankan      html  css  js  c++  java
  • 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,假如还找不到信息。关于疯狂


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




  • 相关阅读:
    使用 richtextbox 输出程序运行信息
    多线程 更新 winform 控件的值,以避免UI线程的卡顿
    多线程 以及 主程序退出时 子线程的销毁
    supersocket 通过配置文件启动服务 总是 初始化失败的 解决办法
    增删改存储过程 框架
    winform DataGridView 通用初始化
    SQLServer存储过程 实例,很多语法可以以后参考
    Winform中 DataGridView控件中的 CheckBox 的值读出来 始终 为 False ,已解决
    winform中 让 程序 自己重启
    字符数组什么时候要加‘’
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4802558.html
Copyright © 2011-2022 走看看