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