iOS 11中tableView下移问题

1.如果不需要系统为你设置边缘距离,可以做以下设置:

//如果iOS的系统是11.0,会有这样一个宏定义“#define __IPHONE_11_0 110000”;如果系统版本低于11.0则没有这个宏定义

ifdef __IPHONE_11_0

if ([tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
if (@available(iOS 11.0, )) {
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
_tableView.contentInset=UIEdgeInsetsMake(0, 0, 0, 0 );
/
属性的解释
/* When contentInsetAdjustmentBehavior allows, UIScrollView may incorporate
its safeAreaInsets into the adjustedContentInset.
@property(nonatomic, readonly) UIEdgeInsets adjustedContentInset API_AVAILABLE(ios(11.0),tvos(11.0));
*/
tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}

endif

contentInsetAdjustmentBehavior属性也是用来取代automaticallyAdjustsScrollViewInsets属性的,推荐使用这种方式。
2。实现代理

pragma mark 此方法加上是为了适配iOS 11出现的问题

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

//设置系统子的分割线对齐

  • (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
    [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
    [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 3月8日下午,我校二年四班学生家长满怀感恩之心,把绣有“授业一丝不苟,解惑无微不至”的锦旗献给了班主任于老...
    梁宇婷_ab7f阅读 548评论 0 0
  • 关键对话“关键对话指的是每个人身上都会发生的和他人的互动行为,是指可影响你生活的那些日常对话......关键对话有...
    唐人生阅读 223评论 0 1
  • 看着这张照片,仿佛时间被定格,情景重现,话音仿佛还在耳边 刚去的时候就在拍卖,那三连画就放在这个位...
    行云流水畅遨游阅读 269评论 1 1