問題:iOS 11.0 tableView頂部出現(xiàn)20間距,如圖:
我的解決方案:在基類控制器中重寫viewWillAppear
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//根據(jù)系統(tǒng)版本去掉自動(dòng)調(diào)整
if ([UIDevice currentDevice].systemVersion.doubleValue >= 11.0) {
//遍歷當(dāng)前視圖的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