UICollectionView细胞,自动布局和布局的CollectionView变化

UICollectionView细胞,自动布局和布局的CollectionView变化

问题描述:

我有一个显示单元的集合视图看起来像用图像,标题和副标题的经典表视图。

I have a collection view which displays cells looking like a classic table view with image, title and subtitle.

我希望能够对布局切换到仅示出在连续的图像,3的网格。

I want to be able to switch the layout to a grid showing only the images, 3 in a row.

集合视图单元格的内容与自动布局的故事板是layouted。该ImageView的有以下限制:

The content of the collection view cell is layouted in a storyboard with auto layout. The imageView has the following constraints:


  • 0领先到左小区边缘

  • 顶0顶端小区边缘

  • 底部0至底部小区边缘

  • 固定宽度

  • 水平空间标签

在布局改变的ImageView应具有零约束到容器的所有边缘,因此,它完全填充。

After the layout change the imageView should have constraints of zero to all edges of the container, so that it fills it completely.

目前,当我改变布局与应用程序崩溃无法同时满足约束条件的时刻。。什么是固定的约束时的布局发生变化的最佳方式,甚至更换电池类?

At the moment when I change the layout the app crashes with Unable to simultaneously satisfy constraints.. What is the best way to fix the constraints when the layout is changed, maybe even replace the cell class?

原来,问题是在code的其他部分。
动画:完成:你可以用 setCollectionViewLayout改变的CollectionView布局。并重新加载可见单元格中完成块

Turns out the problem was in some other part of the code. You can change the collectionView layout with setCollectionViewLayout:animated:completion: and reload the visible cells in the completion block.