14

I am trying to use the so called "self sizing cell" which means:

  • set estimatedItemSize on flowLayout
  • overide preferredLayoutAttributesFittingAttributes in cell class

Such as this: UICollectionView Self Sizing Cells with Auto Layout

And I need dynamic effect like this:http://www.teehanlax.com/blog/implementing-a-bouncy-uicollectionviewlayout-with-uikit-dynamics/

It works fine without UIDynamic, but I need UIDynamic. As what I see, it will call the prepareLayout and layoutAttributesForElementsInRect until die, there will be too many _updateVisibleCellsNow waiting in line.

I have no idea how to solve that, please help me in case u see. Or, if I am using those technologies in wrong way, please let me know.

Community
  • 1
  • 1
iaomw
  • 315
  • 3
  • 13

2 Answers2

12

Two things worked for me:

  • Make sure your collection view itself has layout constraints defined for placement within its superview.
  • I got this crash when the estimated size was larger than the final size. If I set the estimated size to a smaller value the crash stopped.
Chris Garrett
  • 4,474
  • 30
  • 46
  • This is true... Correct answer, I set estimatedItemSize = (0, 0) – Kampai Feb 21 '17 at 07:59
  • For me, setting an `estimatedItemSize` of `.zero` disabled autosizing completely, but a size of (1.0, 1.0) fixed the infinite recursion of `_updateVisibleCellsNow:` on iOS 9 – johnpatrickmorgan Mar 09 '17 at 10:46
1

If any size or frame position changed, it will trigger all cells' preferredLayoutAttributesFittingAttributes until all cells' frames did not change.

The behavior flow is as the following:

1. Before self-sizing cell

2. Validated self-sizing cell again after other cells recalculated.

3. Did changed self-sizing cell

If second steps can't get stable all cells' position and size, it will become infinite loop.

Please reference my post here: UICollectionView Self Sizing Cells with Auto Layout

Community
  • 1
  • 1
Yang Young
  • 376
  • 2
  • 6