zoukankan      html  css  js  c++  java
  • 使用COCOS2D-X JSB开发,在js页面中设置iOS键盘模式

     

    XYSDK.h

    void setKeyboardType(int type);

     

     

    XYSDK.cpp

    voidXYSDK::setKeyboardType(int type)

    {

    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

        CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();

        if (pGlView)

        {

            if (0==type) {

                pGlView->setIMEKeyboardDefault();

            }elseif (1 ==type) {

               pGlView->setIMEKeyboardNumber();

            }

           pGlView->setIMEKeyboardState(true);

        }

    #endif

    }

    CCEGLView

    voidCCEGLView::setIMEKeyboardNumber()

    {

       

        EAGLView * view = [EAGLViewsharedEGLView];

        view.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

       

    }

     

    voidCCEGLView::setIMEKeyboardDefault()

    {

       

        EAGLView * view = [EAGLViewsharedEGLView];

       

        view.keyboardType =UIKeyboardTypeDefault;

       

    }

     

     

    Jsb_xy.hpp

    JSBool js_xy_XYSDK_setKeyboardType(JSContext *cx, uint32_t argc, jsval *vp);

     

    Jsb_xy.cpp

    JSBooljs_xy_XYSDK_setKeyboardType(JSContext *cx, uint32_t argc, jsval *vp)

    {

        jsval *argv = JS_ARGV(cx, vp);

        JSBool ok = JS_TRUE;

        JSObject *obj = JS_THIS_OBJECT(cx, vp);

        js_proxy_t *proxy = jsb_get_js_proxy(obj);

        XYSDK* cobj = (XYSDK *)(proxy ?proxy->ptr : NULL);

        JSB_PRECONDITION2( cobj, cx, JS_FALSE, "InvalidNative Object");

        if (argc == 1) {

            int arg0;

            ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);

            JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");

            cobj->setKeyboardType(arg0);

            JS_SET_RVAL(cx, vp, JSVAL_VOID);

            returnJS_TRUE;

        }

       

        JS_ReportError(cx, "wrong number of arguments: %d, was expecting%d", argc, 1);

        returnJS_FALSE;

    }

    使用

    js文件里,attachWithIME之前设置setKeyboardType

     

    setKeyboardType(0) //默认键盘

    setKeyboardType(1//数字键盘

     

     

    xy.XYSDK.getInstance().setKeyboardType(1);

           this._MainUI.getWidgetByName("TextField_shu_ru").attachWithIME();

  • 相关阅读:
    [哈工大操作系统]一、环境配置
    [算法笔记]带权并查集
    C++:Reference to non-static member function must be called
    [算法笔记]并查集
    C++:string.size()比较问题
    [算法笔记]二分总结
    【LeetCode每日一题】2020.10.15 116. 填充每个节点的下一个右侧节点指针
    1Manjaro的安装
    【《你不知道的JS(中卷②)》】一、 异步:现在与未来
    【LeetCode每日一题】2020.7.14 120. 三角形最小路径和
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3850208.html
Copyright © 2011-2022 走看看