[英]Swift determine if you have enough cells to cover the whole screen
Is there an easy way do determine if you have enough TableViewCells
to cover the whole screen? 有没有一种简单的方法来确定您是否有足够的
TableViewCells
覆盖整个屏幕? Like the whole screen space reserved for the TableView
is covered in cells
. 像为
TableView
保留的整个屏幕空间都被cells
覆盖。
I know you can add up the height of each cell
and the height of group headers
and the StatusBar
and any other elements in the screen and see if the sum if less than the height of the screen of the used device. 我知道您可以将每个
cell
的高度,组headers
的高度和StatusBar
以及屏幕中的任何其他元素的高度相加,然后查看总和是否小于所用设备的屏幕高度。 But is there a more elegant and easier way to know? 但是,有没有一种更优雅,更轻松的方法来知道?
You can count it by something like, 您可以用类似的方法来计算
let tableViewLastPoint = self.yourTableView.tableFooterView!.frame.origin.y + self.yourTableView.tableFooterView!.frame.size.height
then compare that if tableViewLastPoint
is greater than your screen's height then you have cell that requires more height then screen, else cells are not required full screen! 然后比较一下,如果
tableViewLastPoint
大于屏幕的高度,则您的单元格需要比屏幕更高的高度,否则不需要单元格全屏显示!
In this case you should initialize your tableview's footerview with zero frame
like, 在这种情况下,您应该
tableview's footerview with zero frame
来初始化tableview's footerview with zero frame
例如,
self.yourTableView.tableFooterView = UIView.init(frame: CGRectZero)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.