如何设计和设置 UICollectionView 的高度并防止它折叠?

How can I design and set the height of UICollectionView and prevent it for collapsing?

我是 iOS Swift 的初学者,正在尝试制作水平滚动集合视图(如 Android 的回收站视图)。我在这里和 google 搜索了很多次,并尝试了不同的制作教程。

我不熟悉 xCode 故事板和设计界面、约束等的过程,所以我不知道如何设置 CollectionView 的高度并防止它折叠。

我上传了两张截图,一张是故事板,另一张是模拟器。

感谢任何建议。

你需要实施

  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
      return CGSize(width:wid, height:hei) 
  }

class VC :  UICollectionViewDelegate  , UICollectionViewDataSource , UICollectionViewDelegateFlowLayout { }

您需要对集合视图设置最小高度限制 >= 50 例如,最小高度为 50,这应该可以解决您的问题