IOS: a simple method for keyboard occlusion

Source: Internet
Author: User

1. Use uiscrollview settings to move the whole up

Place the controls on the scrollview, and then set cgpointmake (scroll. contentoffset. X, Y + 100) of scrollview when the user clicks to achieve the effect-(void) textfielddidb

-(void)textFieldDidBeginEditing:(UITextField *)textField{    UIScrollView *scroll=(UIScrollView *)self.superview;    float y = 200;    [scroll setContentOffset:CGPointMake(scroll.contentOffset.x, y+100) animated:YES];        }- (void)textFieldDidEndEditing:(UITextField *)textField {            UIScrollView *scroll = (UIScrollView *)self.superview;    [scroll setContentOffset:CGPointMake(scroll.contentOffset.x, 0) animated:YES];    return;}

Remember that these are all controls placed on scrollview,

2. The second method is to move the parent class view up as a whole,

# Pragma mark textkeyboardheight method // first responds to the textfiled method. Because there are multiple controls, tag-(void) textfielddidbeginediting :( uitextfield *) textfield {[self slideframeup: Nil withtag: textfield. tag];}-(void) textfielddidendediting :( uitextfield *) textfield {[self slideframedown: Nil withtag: textfield. tag];} // set up or down-(void) slideframeup :( ID) Up withtag :( nsinteger) Tag {[self slideframe: Yes withtag: Tag];} -(void) slideframedown :( ID) Down withtag :( nsinteger) Tag {[self slideframe: No withtag: Tag];}-(void) slideframe :( bool) Up withtag :( nsinteger) tag {// set the int movementdistance = 1; if (TAG = 3) {movementdistance = 70;} else if (TAG = 4) {movementdistance = 100; // tweak as needed} // determine whether to move up or down. Const float movementduration = 0.3f; // tweak as needed int Movement = (up? -Movementdistance: movementdistance); // animation settings [uiview beginanimations: @ "anim" context: Nil]; [uiview Duration: Yes]; [uiview setanimationduration: movementduration]; self. frame = cgrectoffset (self. frame, 0, movement); [uiview commitanimations];}

The above is a simple method not to be blocked by the keyboard,

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.