iOS - `UICollectionViewCell` 后面的 `UIViews` 消失了

iOS - `UIViews` behind `UICollectionViewCell`disappear

我有一个使用 UICollectionView 的画廊,它是使用 main.storyboard 准备的。我在 UICollectionViewUICollectionViewCell 之间放置了一些 UIViewsUIButton。当我测试应用程序时,一些 UIViewsUIButtons 消失了。

但是我有另一个目录场景,它是用同样的方法准备的,一切都在那里。似乎是什么问题?

我不会以这种方式弄乱 UICollectionView 的视图层次结构。由于它处理自己的子视图列表,因此您的列表可能会受到阻碍。我会建议这两种方法之一:

  1. 将您的 UICollectionView 背景设置为 [UIColor clearColor],然后将您自己的视图 置于 那个 UICollectionView 之后,在类似于这样的层次结构中:

    • UIView
      • 您的自定义视图
      • UICollectionView
  2. 使用 UICollectionView 的 decoration views。您可以在 "Including Decoration Views in Your Custom Layouts" 部分阅读有关它们的更多信息 here

    Decoration views are visual adornments that enhance the appearance of your collection view layouts. Unlike cells and supplementary views, decoration views provide visual content only and are thus independent of the data source. You can use them to provide custom backgrounds, fill in the spaces around cells, or even obscure cells if you want. Decoration views are defined and managed solely by the layout object and do not interact with the collection view’s data source object.