iOS 11 UITableView的额外顶部空间
当我在iOS 11 SDK上更新我的应用程序时,TableView开始表现奇怪,它增加了额外的顶部空间,但实际上额外的空间是Cell本身,但它没有渲染,请通过附加在ios 11更新之前和之后的图像。 谢谢!iOS 11 UITableView的额外顶部空间
我们在iOS上的11项目中的保存问题,2种方式是有用的我的项目如下:
1.添加委托方法:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [UIView new]; }
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; }
2.设置的UITableView contentInset:
tableView.contentInset = UIEdgeInsetsMake(-25, 0, 0, 0);
的.TOP值取决于你的UI设计。
嵌入式硬编码是一个可怕的想法。 –
我不知道为什么,但当我以编程方式添加表视图发生空间。你需要的是在viewForHeaderInSection
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
返回空视图如果你想零空间,添加它也
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.01
}
而且,我意识到,错误只出现在Swift4。
在代码中设置新属性contentInsetAdjustmentBehavior
,它会解决问题。
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
上有UIScrollView的偏移
此属性指定的安全区域插图用于修改 滚动的内容区域一个新的属性称为iOS的11加
contentInsetAdjustmentBehavior
确定调整内容视图。此 属性的默认值是自动的。
把这个放在哪里? –
只是发生在iOS上11对我来说,我的解决办法:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
OR
self.tableView.tableHeaderView = UIView(frame: CGRect(x:0,y:0,width:0,height:CGFLOAT_MIN))
请分享代码还@lekve –