问题描述
swift 5 当push到一个包含UITableView的viewController的时候,当initTableView
为.plain
或者 .grouped
时有时候会出现sectionHeaderView/footerHeaderView 或者 tableHeaderView/tableFooterView 的偏移,这个偏移即使去设备tableView.contentInset也是达不到预期的效果的,(其实不算是偏移,是tableView默认值,所以会看到明明没有设置tableHeader.height, 也没有设置sectionHeader.height 和 sectionFooter.height ,却出现了)
具体表现为:
.plain sectionHeader/sectionFooter位置问题 | .grouped tableHeader/tableFooter位置问题 |
---|---|
![]() |
![]() |
解决办法:
直接给它们设置一个最小值来去掉这个默认值:
// for tableHeaderView and tableFooterView
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
// for sectionHeaderView and sectionFooterView
tableView.sectionHeaderHeight = CGFloat.leastNormalMagnitude
tableView.sectionFooterHeight = CGFloat.leastNormalMagnitude
网友评论