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();

  • 相关阅读:
    论文才考文献批量修改上角标
    Java开发工具打包下载
    navcat导入mdf文件教程
    net::ERR_INCOMPLETE_CHUNKED_ENCODING
    springboot利用AbstractRoutingDataSource实现动态切换数据源
    springboot利用ConfigurationProperties注解配置数据源无法读取配置信息
    with opne()
    专职DBA-基于Dcoker环境初始化三台虚拟机
    因为下游MySQL的sql_mode设置与上游TiDB的sql_mode不一样,导致drainer同步状态下线。
    Mysql语句
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3850208.html
Copyright © 2011-2022 走看看