Workaround for keyboard obscured text boxes

Source: Internet
Author: User

For the processing of the keyboard mask text box, take the user login as an example. There are two ways to do this, and the second is relatively simple.
The test found that the ipad Mini and the ipad Air are different in height, just the opposite. The mini width is 1024, the height is 768;air width is 768, the height is 1024.
Therefore, it is necessary to determine the suitability of these two devices.

1CGFloat deviceheight =[UIScreen mainscreen].bounds.size.height;2CGFloat devicewidth =[UIScreen mainscreen].bounds.size.width;3CGFloat BACKGROUNDVIEWW =0;4 //device is mini5 if(Devicewidth >deviceheight) {6BACKGROUNDVIEWW =Devicewidth;7}Else{//Device is air8BACKGROUNDVIEWW =Deviceheight;9}

Here's how to troubleshoot a keyboard that obscures a text box.

Method One:

1- (void) viewdidload{2 [Super Viewdidload];3     4     //Add Login Interface5 [self setuploginview];6     7     //Listen text Box8 [self Listentextfield];9     Ten     //Click Other area to hide the keyboard One [self hidekeyboardwithclickarea]; A}
1 //monitoring of account number and password input box2-(void) listentextfield{3 [Self.accountfield addtarget:self Action: @selector (Textfieldbeginedit:) forControlEvents: Uicontroleventeditingdidbegin];4 [Self.accountfield addtarget:self Action: @selector (Textfieldendedit:) forControlEvents: Uicontroleventeditingdidend];5 [Self.passwordfield addtarget:self Action: @selector (Textfieldbeginedit:) forControlEvents: Uicontroleventeditingdidbegin];6 [Self.passwordfield addtarget:self Action: @selector (Textfieldendedit:) forControlEvents: Uicontroleventeditingdidend];7 }8 9 //when you start editing, the whole move upTen-(void) Textfieldbeginedit: (Uitextfield *) textfield{ One[Self moveview:- Max]; A } -  - //when you finish editing, move back to the original location the-(void) Textfieldendedit: (Uitextfield *) textfield{ -[Self Moveview: Max]; -}
1 //the specific method of view movement2-(void) Moveview: (float) move{3Nstimeinterval animationduration =0.3f;4CGRect frame =Self.view.frame;5CGFloat deviceheight =[UIScreen mainscreen].bounds.size.height;6CGFloat devicewidth =[UIScreen mainscreen].bounds.size.width;7     //determine if the device is an ipad Air and is inverted8     if(Deviceheight > Devicewidth && self.interfaceorientation==4) {9         //The x-axis of the view moves up, pad airTenFrame.origin.x + =move; One}Else if(Deviceheight > Devicewidth && self.interfaceorientation==3){ AFrame.origin.x-=move; -}Else{//for Mini -FRAME.ORIGIN.Y + =move; the     } -      -Self.view.frame =frame; -[UIView beginanimations:@"2"Context:nil];//2 is the logo of the animation, + [UIView setanimationduration:animationduration]; -Self.view.frame =frame; + [UIView commitanimations]; A}
1 //Click Other areas to hide the keyboard2-(void) hidekeyboardwithclickarea{3UITapGestureRecognizer *gesture =[[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (Hidekeyboard)];4     //confirm that you clicked other areas instead of double- clicking other actions5gesture.numberoftapsrequired =1;6 [Self.view addgesturerecognizer:gesture];7     8     //Click the "Hide Keyboard" button in the lower right corner of the keyboard to close the keyboard and restore the view location9[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (hidekeyboard) Name: UikeyboardwillhidenotificationObject: nil];Ten } One  A-(void) hidekeyboard{ - [Self.accountfield Resignfirstresponder]; - [Self.passwordfield Resignfirstresponder]; the [self resumeview]; - } -  - //Restore View's original location +-(void) resumeview{ -Nstimeinterval animationduration=0.5f; +[UIView beginanimations:@"3"Context:nil]; A [UIView setanimationduration:animationduration]; at [UIView commitanimations]; -}

Method Two:

This method is very simple, but also very lazy, once and for all.

is to search Iqkeyboardmanager from GitHub and put it directly into the project!

Workaround for keyboard obscured text boxes

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.