最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[整理]iOS中的systemLayoutSizeFittingSize

iOS crifan 6604浏览 0评论

看:

feiin/swiftmi-app: swiftmi.com app版本 采用Swift实现

的源码中看到了:

<code>        let size = self.prototypeCell!.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
</code>

去搜:

systemLayoutSizeFittingSize

Autolayout小结(二) – 刘坤的技术博客

动态计算UITableViewCell高度详解 – Haven’s Blog

深入理解Auto Layout 第一弹 | 张不坏的博客

动态计算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

ios – Calling `[UIView -systemLayoutSizeFittingSize:]` on a UITableViewCell always fails – Stack Overflow

使用AutoLayout动态计算UITableViewCell高度 – lcg0412的专栏 – 博客频道 – CSDN.NET

objective c – Wrong size returned by systemLayoutSizeFittingSize when using multiline label – Stack Overflow

objective c – How can a get the auto layout size of the UICollectionViewCells in iOS 8? (systemLayoutSizeFittingSize returns size with zero height in iOS 8) – Stack Overflow

A Better Way to Autosize in iOS 8

去试了试,结构都没有一个能完全精准的:

<code>var eachNewRowHeight:CGFloat = self.tableView(self.messageTableView, heightForRowAtIndexPath: eachRowIndexPath)

//when return UITableViewAutomaticDimension -&gt; value is -1 !!!
//so need adjust height value
if eachNewRowHeight &lt; 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

forkingdog/UITableView-FDTemplateLayoutCell: Template auto layout cell for automatically UITableViewCell height calculating

另外,这个:

ios – Using Auto Layout in UITableView for dynamic cell layouts & variable row heights – Stack Overflow

也值得参考

-》减少无谓的冗余的cell的高度计算

-》增加滚动流畅度

转载请注明:在路上 » [整理]iOS中的systemLayoutSizeFittingSize

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.175 seconds, using 22.12MB memory