ios - 使用 UICollectionViewDelegateFlowLayout 后约束未更新
问题描述
我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)
}
因此,委托方法设置了正确的大小,但单元格中的元素被剪切(未更新)。我的单元格约束在情节提要中设置。
解决方案
没有太多细节,我想你可能需要:
viewWillLayoutSubviews()
调用以通知视图控制器其视图即将布局其子视图。
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621437-viewwilllayoutsubviews
或者
layoutSubviews()
https://developer.apple.com/documentation/uikit/uiview/1622482-layoutsubviews
推荐阅读
- java - 如何过滤 Spring 的页面
对象使用 java8 的 filter() 并返回 Page - powershell - 如何将 Invoke-SilentlyAndReturnExitCode 实现为 Powershell 模块功能?
- powershell - 使用 powershell 进行文本操作
- android - Android 在消息应用程序中输入动画
- mysql - 在mysql数据库中存储多个用户数据的最佳方法是什么?
- r - 在 R 中使用 Rank 函数时包括前导零
- c - 这个malloc错误是什么意思?损坏的顶部尺寸?
- php - 显示 WooCommerce 产品属性的自定义分类术语图像
- python - 无法使用 selenium、python 和 chromedriver 与页面中的元素交互
- c - 在链表末尾添加数据的函数