iOS11屏幕适配(iphone X、tableView内容下移)

1.无法顶到屏幕最上方


iOS11屏幕适配(iphone X、tableView内容下移)_第1张图片
ios11屏幕

2.解决方法

// tableView 偏移20/64适配

if(@available(iOS11.0, *)) {self.tableView.contentInsetAdjustmentBehavior =UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用}else{self.automaticallyAdjustsScrollViewInsets =NO;}

// tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理

- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section{return10;}- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section{return0.1;}- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {return[[UIViewalloc] init];}- (UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section {return[[UIViewalloc] init];}

3.写两个宏:

#defineAdjustsScrollViewInsetNever(controller, view)if(@available(iOS 11.0, *)) {view.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;}else if([controller isKindOfClass:[UIViewController class]]) {controller.automaticallyAdjustsScrollViewInsets = false;}

#defineUITableViewEstimatedHeight(tableView) \if(@available(iOS 11.0, *)) { \ tableView.estimatedRowHeight = 0; \ tableView.estimatedSectionHeaderHeight = 0; \ tableView.estimatedSectionFooterHeight = 0; \ }

你可能感兴趣的:(iOS11屏幕适配(iphone X、tableView内容下移))