问题:iOS 11.0 tableView顶部出现20间距,如图:
我的解决方案:在基类控制器中重写viewWillAppear
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//根据系统版本去掉自动调整
if ([UIDevice currentDevice].systemVersion.doubleValue >= 11.0) {
//遍历当前视图的subviews
for (id obj in CurControllerView.subviews) {
if ([obj isKindOfClass:[UITableView class]]) {
[obj setValue:@2 forKey:@"contentInsetAdjustmentBehavior"];
}
}
}else{
self.automaticallyAdjustsScrollViewInsets = NO;
}
}
原理:
在iOS 11中automaticallyAdjustsScrollViewInsets废弃,改用scrollView的automaticallyAdjustsScrollViewInsets
网友评论