COCOS2DX 2.2.5 Cceditbox IOS adaptation issues

Source: Internet
Author: User

Cceditbox is normal on the ipad, but when clicked to edit, the text doesn't fit, or the iphone is small!

First find the following function in the Cceditbox source file:

void Cceditbox::touchdownaction (Ccobject *sender, Cccontrolevent controlevent) {    M_peditboximpl-  Openkeyboard ();}

Very clear, here is the keyboard open (unless your English is not pass it!) )! Here M_peditboximpl is Cceditboximpl Class!

Go directly to the header file of this class and find here the Openkeyboard () function, which is a virtual function:

Virtual void 0;

Then, find the header file for this class Cceditboximplios, which inherits the Cceditboximpl class

In this header file, however, a openkeyboad function is found: (This function is written in objective-c)

-(void) Openkeyboard;

 

Open the source file for Cceditboximplios, and then find the following function implementation: (very familiar with it, yes, this is the virtual function in the Cceditboximpl Class!) Rewrite it in the Cceditboximplios source file! )

void Cceditboximplios::openkeyboard () {m_plabel->setvisible (false); m_plabelplaceholder->setvisible (false); M_systemControl.textField.hidden = NO;        [M_systemcontrol Openkeyboard];}

Last Call to [M_systemcontrol Openkeyboard]; The implementation of the function is as follows, here is the code of OBJECTIVE-C, we can modify it here, and finally I choose to change in the cceditboximplios of the overlay function;

-(void) openkeyboard{    [[Eaglview Sharedeglview] addsubview:textfield_];    [Textfield_ Becomefirstresponder];}

The design screen size of our game is 960*640; First we get a multiple of the zoom of the screen x and y; then we get the standard stretch multiples.

    ccdirector* PDIRECOTR = Ccdirector::shareddirector ();    float ScaleX = Pdirecotr->getwinsizeinpixels (). width/960;    float ScaleY = Pdirecotr->getwinsizeinpixels (). height/640;    Float scale = ScaleX > ScaleY? Scaley:scalex;            Get Standard stretch Multiples

 

The size of the M_systemcontrol. TextField is then multiplied by the standard stretch size scale, and then the M_systemcontrol is set. The size of theTextField font multiplied by the standard extrude scale

Directly on the code:

void Cceditboximplios::openkeyboard () {m_plabel->setvisible (false); m_plabelplaceholder->setvisible (false); /******* * * * Add by Author:zero * * * Description:cceditbox adaptation issue, here is just iOS *******/ccdirector* Pdireco    TR = Ccdirector::shareddirector ();    float ScaleX = Pdirecotr->getwinsizeinpixels (). width/960;    float ScaleY = Pdirecotr->getwinsizeinpixels (). height/640; Float scale = ScaleX > ScaleY?    Scaley:scalex;    Cgsize size = [M_systemcontrol.textfield frame].size;        [M_systemcontrol setcontentsize:cgsizemake (size.width * scale, Size.Height * scale)];    M_isfirsttouch is the bool type variable defined by the header file, the set value in the initialization list is true;//the size of the M_systemcontrol.textfield is set when the first time you come in, otherwise, the field becomes larger once per click!        if (M_isfirsttouch) {cgfloat height = m_systemControl.textField.font.pointSize;        M_systemControl.textField.font = [Uifont Systemfontofsize:height*scale];    M_isfirsttouch = false;    }m_systemcontrol.textfield.hidden = NO; [M_SYSTEMCOntrol Openkeyboard];} 

Put it on, it's ready! The Fit is perfect!

COCOS2DX 2.2.5 Cceditbox IOS adaptation issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.