When the keyboard pops up, UITableView content moves up, not being blocked by the keyboard, causing UITableView content to display

Source: Internet
Author: User

First register the notification, monitor the keyboard:

-(void) viewdidload {    [super viewdidload];    [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillappear:) Name: Uikeyboardwillshownotification Object:nil];    [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwilldisappear:) Name: Uikeyboardwillhidenotification Object:nil];}

Do the following in the keyboard pop-up and pick-up method:

-(void) Keyboardwillappear: (nsnotification *) Noti {nsdictionary *userinfo = Noti.userinfo;    Get the keyboard frame cgrect keyboardframe = [[UserInfo Objectforkey:uikeyboardframeenduserinfokey] cgrectvalue]; Get keyboard pop-up animation time nstimeinterval animationduration = [[UserInfo Objectforkey:uikeyboardanimationdurationuserinfokey]    Doublevalue]; Let the input box follow the change [UIView animatewithduration:animationduration animations:^{[_CTV mas_updateconstraints:^ (MASConstrain       Tmaker *make) {make.bottom.equalTo (-keyboardframe.size.height);    }];    }]; Set the Contentinset property of the TableView, change the display range of the TableView _tableview.contentinset = uiedgeinsetsmake (0, 0,    KeyboardFrame.size.height, 0); _tableview.scrollenabled = YES;}    -(void) Keyboardwilldisappear: (nsnotification *) Noti {nsdictionary *userinfo = Noti.userinfo;    Nstimeinterval animationduration = [[UserInfo Objectforkey:uikeyboardanimationdurationuserinfokey] doubleValue]; [UIView animatewithduration:animationduration Animations:^{[_CTV mas_updateconstraints:^ (Masconstraintmaker *make) {make.bottom.equalTo (@0);        Make.height.equalTo (@52);    }];    }];    Uiedgeinsets contentinsets = Uiedgeinsetszero; _tableview.contentinset = contentinsets;}

When the keyboard pops up, UITableView content moves up, not being blocked by the keyboard, causing UITableView content to display

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.