UITableView 防止自动偏移

// 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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容