1

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

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

Mockup of the two layouts

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

  • Leading 0 to the left cell edge
  • Top 0 to the top cell edge
  • Bottom 0 to the bottom cell edge
  • Fixed width
  • Horizontal space to the labels

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?

Cornelius
  • 4,214
  • 3
  • 36
  • 55

1 Answers1

1

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.

Cornelius
  • 4,214
  • 3
  • 36
  • 55
  • 2
    Hi Mark, I am having an issue when animating to the destination layout. For some reason my image view 'snaps' to its end key frame as soon as the animation starts. How did you get around this? – Marty W Dec 30 '13 at 23:11
  • 1
    Same here Mark, at the end of the animation the cell subview frames are all screwed up – Thiago Peres Jan 19 '14 at 12:17