我使用的是带有默认 UICollectionViewFlowLayout
的 UICollectionView:
let layout = UICollectionViewFlowLayout()
layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
我的自定义单元格是:
class CVLegislationCell : UICollectionViewCell {
let card = CardView() // A view that uses auto layout
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup()
{
self.contentView.addSubview(card)
card.constrain_edges(to: contentView) // convenience function I wrote for auto layout
}
}
由于某种原因,我遇到各种自动布局错误,并且尺寸出现错误。我是否错误地子类化了?
最佳答案
当您将卡片添加为 subview 时,您没有使用 super View 自动布局它。那是与细胞有关。只需使用单元格以编程方式添加自动布局即可。
关于ios - UICollectionView 导致单元格自动布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44267991/