Swift编程

UITableView tableHeader/sectionH

2019-11-07  本文已影响0人  追风筝的荧火虫

问题描述

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位置问题
可以看到这个footer一直在这里停留 没有设置tableHeader,但可以看到这里出现了

解决办法:

直接给它们设置一个最小值来去掉这个默认值:

// 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
上一篇 下一篇

猜你喜欢

热点阅读