看:
feiin/swiftmi-app: swiftmi.com app版本 采用Swift实现
的源码中看到了:
<code> let size = self.prototypeCell!.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) </code>
去搜:
systemLayoutSizeFittingSize
动态计算UITableViewCell高度详解 – Haven’s Blog
动态计算UITableViewCell高度详解 – CocoaChina 苹果开发中文站 – 最热的iPhone开发社区 最热的苹果开发社区 最热的iPad开发社区
UITableVIew的高度和AutoLayout – 简书
但是自己参考:
Using auto-layout to calculate table cell height — Amy Worrall’s Blog
ios – Why is systemLayoutSizeFittingSize returning (0, 0) for UITableViewCell? – Stack Overflow
ios – uitablviewcell dynamic height is not correct from systemLayoutSizeFittingSize – Stack Overflow
使用AutoLayout动态计算UITableViewCell高度 – lcg0412的专栏 – 博客频道 – CSDN.NET
A Better Way to Autosize in iOS 8
去试了试,结构都没有一个能完全精准的:
<code>var eachNewRowHeight:CGFloat = self.tableView(self.messageTableView, heightForRowAtIndexPath: eachRowIndexPath)
//when return UITableViewAutomaticDimension -> value is -1 !!!
//so need adjust height value
if eachNewRowHeight < 0.0 {
//eachNewRowHeight = MessageTableViewCell.calculateCellHeight(curMsg)
let calcHeight = MessageTableViewCell.calculateCellHeight(curMsg)
let curCell = self.tableView(self.messageTableView, cellForRowAtIndexPath: eachRowIndexPath)
curCell.setNeedsLayout()
curCell.layoutIfNeeded()
curCell.layoutSubviews()
curCell.contentView.layoutIfNeeded()
// eachNewRowHeight = curCell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
var fittingSize = UILayoutFittingCompressedSize
fittingSize.width = UIScreen.mainScreen().bounds.width
eachNewRowHeight = curCell.contentView.systemLayoutSizeFittingSize(fittingSize, withHorizontalFittingPriority: 1000, verticalFittingPriority: 250).height
// eachNewRowHeight = curCell.contentView.systemLayoutSizeFittingSize(UILayoutFittingExpandedSize).height
if calcHeight != eachNewRowHeight {
gLog.debug("\(curMsg.id) fittingSize=\(fittingSize), calculateCellHeight=\(calcHeight), systemLayoutSizeFittingSize.height=\(eachNewRowHeight)")
}
</code>有空继续去尝试
搜:
ios 自动布局 uitableviewcell 高度计算
UITableViewCell 高度计算从混沌初始到天地交泰 – 简书
抽空去:
参考:
优化UITableViewCell高度计算的那些事 · sunnyxx的技术博客
使用:
FDTemplateLayoutCell
另外,这个:
也值得参考
-》减少无谓的冗余的cell的高度计算
-》增加滚动流畅度