【问题标题】:UICollectionView causes autolayout issues with cellsUICollectionView 导致单元格的自动布局问题
【发布时间】:2017-05-30 17:01:25
【问题描述】:

我正在使用带有默认 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
    }
}

由于某种原因,我得到了各种自动布局错误,并且尺寸错误。我的子类化不正确吗?

【问题讨论】:

  • 您需要将layout.estimatedItemSize设置为实际值

标签: ios swift uicollectionview autolayout


【解决方案1】:

当您将卡片添加为子视图时,您没有使用超级视图自动布局。那是与细胞。只需通过单元格以编程方式添加自动布局。

【讨论】:

  • 我不太明白你在说什么
猜你喜欢
  • 2015-08-19
  • 2013-10-26
  • 2015-03-13
  • 2014-09-02
  • 1970-01-01
  • 2017-05-07
  • 2020-09-10
  • 2014-11-11
相关资源
最近更新 更多