Simple way to solve the keyboard occlusion text box

Source: Internet
Author: User

1, first need to add the previous ScrollView in the controller's view, and follow the uitextfielddelegate agent, and set the text box itself agent

2. Add gesture Monitoring

     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Taptouch:)];    [Self.scrollerview Addgesturerecognizer:tap];

-(void) Taptouch: (uigesturerecognizer*) gesture{        [Self.view Endediting:yes];    [Self.username Resignfirstresponder];    [Self.password Resignfirstresponder];    [Self.checkpassword  Resignfirstresponder];    [Self.phonenumber Resignfirstresponder];    [Self textfielddidbeginediting:0];}

3, set the appropriate code in the proxy method

-(void) textfielddidbeginediting: (Uitextfield *) textfield{    cgrect rect = self.scrollerView.frame;    [UIView Beginanimations:nil context:null];    [UIView setanimationduration:0.3];        if (TextField = = Self.username)    {        rect.origin.y = 0;    } else if (TextField = = Self.password)    {        rect.origin.y = -50;    }    else if (TextField = = Self.checkpassword)    {        rect.origin.y = -80;    }    else if (TextField = = Self.phonenumber)    {        rect.origin.y = -100;    } else    {        rect.origin.y = 0;    }    Self.scrollerView.frame = rect;    [UIView commitanimations];        }

Get

Simple way to solve the keyboard occlusion text box

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.