gpt4 book ai didi

ios - UICollectionView 导致单元格自动布局问题

转载 作者:行者123 更新时间:2023-11-30 12:25:33 25 4
gpt4 key购买 nike

我使用的是带有默认 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com