iOS11 系统 UITableView 下移 问题

在最近的一个项目开发中, 遇到了 iOS11系统 UITableView 下移动的问题,从网上搜搜了有许多解决方法:例如
方案一:

//如果iOS的系统是11.0,会有这样一个宏定义“#define __IPHONE_11_0  110000”;如果系统版本低于11.0则没有这个宏定义
#ifdef __IPHONE_11_0   
if ([tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
    tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
#endif

方案二:

如果需要全局设置的话,需要这么设置:

if (@available(iOS 11.0, *)) {
 [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}

这样设置后使用UITableview 、UICollectionView、UIScrollview的时候就不需要再单独设置该属性了,因为UIView以及他的子类都是遵循UIAppearance协议的。

很遗憾的是, 问题依然存在,并没有什么卵用.
tableView就要设置成plain而不是group如果是group那就只能修改代理方法,把viewForHeaderviewForFooter设置为nil(前提是你的headerfooter都没有用,如果本身就在header或者footer写了内容,就不需要改了,不会变形的)

最后在代理方法里进行了相应设置就好了.希望能有所帮助.

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

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

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

你可能感兴趣的:(iOS11 系统 UITableView 下移 问题)