使用COCOS2D-X JSB開發,在js頁面中設定iOS鍵盤模式

來源:互聯網
上載者:User

標籤:style   color   使用   os   檔案   art   

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.