COCOS2DX 2.2.5 Cceditbox IOS adaptation issues

Source: Internet
Author: User

Recently doing cceditbox, found that after the click, the text is not suitable for

Compare today, so solve this problem

The function to find the response when Cceditbox clicked is Cceditboximplios::openkeyboard

We can see what this function says:

-(void) Openkeyboard

{    

[[Eaglview sharedeglview] addsubview: Textfield_]; Add as SubView

[textfield_ Becomefirstresponder];

}

I did not deal with the textfield_ at all, so I took care of the textfield_.

Because of the Objective-c class properties are not familiar with, so asked a degree Niang, this is not the way!

So think, textfield_ must initialize, so in Cceditboximplios this source file, found the following code

-(ID) initWithFrame: (cgrect) Framerect editbox: (void*) editbox{self = [super init];        Do {if (self = = nil) break;        Editstate_ = NO;  Self.textfield = [[[Customuitextfield alloc] initwithframe:framerect] autorelease];        Initializes a frame if (!textfield_) break;        [Textfield_ Settextcolor:[uicolor Whitecolor];           Textfield_.font = [Uifont SYSTEMFONTOFSIZE:FRAMERECT.SIZE.HEIGHT*2/3];        Initialize fonttextfield_.contentverticalalignment = Uicontrolcontentverticalalignmentcenter;        Textfield_.backgroundcolor = [Uicolor Clearcolor];        Textfield_.borderstyle = Uitextborderstylenone;        Textfield_.delegate = self;        Textfield_.hidden = True;textfield_.returnkeytype = Uireturnkeydefault;        [Textfield_ addtarget:self Action: @selector (textChanged) forcontrolevents:uicontroleventeditingchanged];                        Self.editbox = EditBox;    return self;        }while (0); return nil;}

  

The following three lines of code are referenced:

        Self.textfield = [[[Customuitextfield alloc] initwithframe:framerect] autorelease];        if (!textfield_) break;        [Textfield_ Settextcolor:[uicolor Whitecolor];        

 

Added the following code

-(void  ) openkeyboard{ /*  ****** * * * * Add by Author:zero * * * Description:cceditbox iOS adaptation issues  */  CGFloat scale  = [[Eaglview Sharedeglview] contentscalefactor];    CGRect rect  = [Textfield_ frame]; Textfield_.font  = [Uifont systemfontofsize:[textfield_ frame].size.height * scale*    2 /]; [Textfield_ Setframe:cgrectmake (rect.origin.x, RECT.ORIGIN.Y, rect.size.width  * scale, Rect.size.height * scale)];    [[Eaglview Sharedeglview] addsubview:textfield_]; [Textfield_ Becomefirstresponder];}  

Finally get the perfect result!

COCOS2DX 2.2.5 Cceditbox IOS adaptation issues

Related Article

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.