美文网首页
UITableView 防止自动偏移

UITableView 防止自动偏移

作者: 闻人歌 | 来源:发表于2019-09-29 17:44 被阅读0次

// tableView 不随导航栏偏移
if (@available(iOS 11.0, *)) {
self.tbView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else{
self.automaticallyAdjustsScrollViewInsets = NO;
}

  • 使用UITableViewStyleGrouped 类型的UITableView
    在使用此类UITableView 时,也会发生自动偏移的情况,存在的情况:UITableViewCell 向下偏移 35;因为在实现的时候,会自动设置UITableView Herder 的高度,所以需要自己设置其Header 高度为 CGFLOAT_MIN;

    解决办法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
        return CGFLOAT_MIN; 
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

相关文章

网友评论

      本文标题:UITableView 防止自动偏移

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