iOS keyboard occlusion input box, input area automatically move up

Source: Internet
Author: User

In the iOS development process, encountered on the keyboard occlusion input box problem, after network reference and practice, summarized as follows:

Login window, placed up and down two Uitextfield, a username, a password, placed in the bottom of the screen 1/3, when clicked on the user name, automatically eject the keyboard, just block the input box

Solution Ideas:

1, Bloginviewcontroller realization of Uitextviewdelegate method

1  //implements the method in Uitextfielddelegate, automatically moves the input box up when the keyboard pops up when the TextField is edited2-(BOOL) textfieldshouldbeginediting: (Uitextfield *) textfield{3Nstimeinterval animationduration=0.30f;4[UIView beginanimations:@"Resizeforkeyboard"Context:nil];5 [UIView setanimationduration:animationduration];6      floatwidth =Self.view.frame.size.width;7      floatHeight =Self.view.frame.size.height;8      //move n units up, set according to the actual situation9CGRect Rect=cgrectmake (0.0f,- the, width,height);TenSelf.view.frame=rect; One [UIView commitanimations]; A      returnYES; -}

2. Set up an agent for the input box

1- (void) Viewdidload2 {3 [Super Viewdidload];4      5      //status bar White font6 [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent];7      8Uicolor *btnbgcolor = [Uicolor colorwithwhite:1.0fAlpha1.0];9 [_buttonlogin Setbackgroundcolor:btnbgcolor];Ten       One      //add an agent to the input box A_textfieldusername.Delegate=Self ; -_textfieldpassword.Delegate=Self ; -  the}

Effect:

Reference: http://blog.csdn.net/ryantang03/article/details/8203605

iOS keyboard occlusion input box, input area automatically move up

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.