3 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
更新SWIFT 4
systemLayoutSizeFittingSize
systemLayoutSizeFitting
為IOS 9更新
TL;DR
1.成套 estimatedItemSize
在……上面 UICollectionViewFlowLayout
estimatedItemSize
self.flowLayout.estimatedItemSize = CGSize(width: 100, height: 100)
2.在單元格子類上添加對(duì)調(diào)整大小的支持。
preferredLayoutAttributesFittingAttributes
.
使用自動(dòng)布局創(chuàng)建和配置單元格
awakeFromNib
).
實(shí)施 preferredLayoutAttributesFittingAttributes
在您的自定義單元格中
cellForItem
//forces the system to do one layout passvar isHeightCalculated: Bool = falseoverride func preferredLayoutAttributesFittingAttributes (_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { //Exhibit A - We need to cache our calculation to prevent a crash. if !isHeightCalculated { setNeedsLayout() layoutIfNeeded() let size = contentView.systemLayoutSizeFitting(layoutAttributes.size) var newFrame = layoutAttributes.frame newFrame.size.width = CGFloat(ceilf(Float(size.width))) layoutAttributes.frame = newFrame isHeightCalculated = true } return layoutAttributes}
注preferredLayoutAttributesFittingAttributes
isHeightCalculated
體驗(yàn)?zāi)愕牟季?/trans>
UITableView
警告
Undefined
traitCollection

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊
UICollectionViewFlowLayout.automaticSize
UICollectionViewFlowLayoutAutomaticSize
self.flowLayout.estimatedItemSize = CGSize(width: 100, height: 100)
self.flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
- 3 回答
- 0 關(guān)注
- 3088 瀏覽
添加回答
舉報(bào)