美文网首页
iOS 11中tableView下移问题

iOS 11中tableView下移问题

作者: wusa | 来源:发表于2018-07-20 11:05 被阅读0次

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];
    }
    }

相关文章

网友评论

      本文标题:iOS 11中tableView下移问题

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