美文网首页
UITableViewController 处理键盘遮挡问题

UITableViewController 处理键盘遮挡问题

作者: 西风那个吹呀吹 | 来源:发表于2021-06-08 18:39 被阅读0次

UITableViewCell中有UITextViewUITextField,存在一定的键盘遮挡输入框问题。
最简单的处理方法就是利用系统的UITableViewController中的tableView

- (UITableView *)tableView {
    if (!_tableView) {
        UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
        [self addChildViewController:tvc]; // 必加
        _tableView = tvc.tableView;
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        [self.view addSubview:_tableView];
        
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}

现在有一个问题:

[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

如上设置了UIScrollViewcontentInsetAdjustmentBehavior属性为UIScrollViewContentInsetAdjustmentNever,contentInset 不会被调整。
所以,这种情况下,UITableViewController无法处理键盘遮挡问题。

相关文章

网友评论

      本文标题:UITableViewController 处理键盘遮挡问题

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