我正在使用UICollectionViewDelegateFlowLayout
来设置collectionViewCell
的大小和高度,但是当我使用它时,cell
中的约束不会更新。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: UIScreen.main.bounds.width - 30, height: self.height)
}
因此,委托方法设置了正确的大小,但是单元格中的元素被剪切(不更新)。我的单元格约束在情节提要中设置。
答案 0 :(得分:1)
没有太多细节,我想您可能需要:
viewWillLayoutSubviews()
被调用以通知视图控制器其视图将要布局其子视图。
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621437-viewwilllayoutsubviews
或
layoutSubviews()
https://developer.apple.com/documentation/uikit/uiview/1622482-layoutsubviews