美文网首页
tableViewcell有输入时键盘遮挡处理

tableViewcell有输入时键盘遮挡处理

作者: 静守幸福 | 来源:发表于2019-09-29 14:53 被阅读0次

监听键盘弹出和收回 UIKeyboardWillHideNotification UIKeyboardWillShowNotification

方法

  NSDictionary*info=[notificationuser Info];

    CGPoint kbOrigin=[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].origin;

    CGSize kbSize=[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;

kbSizeHeight=main_Height- kbSize.height;

mark - 单个cell直接获取  多个写个回调记录下cell  在回调里进行处理 

//1.获取输入所在cell相对于屏幕的位置

 CGRect frame = [self.tableView convertRect:cell.frame toView:[UIApplication sharedApplication].keyWindow];

//2. 记录原先tableView的偏移量 在回收键盘的时候偏移到原先的偏移量

 contentOffHeight = self.myTableView.contentOffset.y;

//3.判断是否需要偏移

frame.origin.y + 到输入框的高度 > kbSizeHeight

//4. 偏移

offset = contentOffHeight+ frame.origin.y+到输入框的高度 - kbSizeHeight;

//5.动画

        [UIView animateWithDuration:0.25 animations:^{

            self.myTableView.contentOffset=CGPointMake(0, offset);

        }];

相关文章

网友评论

      本文标题:tableViewcell有输入时键盘遮挡处理

      本文链接:https://www.haomeiwen.com/subject/hzpfpctx.html