How to resize a UICollectionView so that it fully displays its contents? I tried many things, including setting up its frame, calling reloadData and layout invalidation:
self.collectionView.contentSize = CGSizeMake(300, 2000); self.collectionView.frame = CGRectMake(0, 0, 300, 2000); [self.collectionView reloadData]; [self.collectionView.collectionViewLayout invalidateLayout];
but none of this has any effect. After clicking the button, I still see the initial view, for example:

I have a small demo program where I have a data source producing 100 elements. In Interface Builder, I initially set the size of the UICollectionView to a small value so that not all elements match, after which I press the button, after which the code above is executed. I expect the UICollectionView to now show all the elements, but that is not the case.
EDIT: Demo program can be found at https://github.com/mjdemilliano/TestUICollectionView .
EDIT2: I noticed that the frame update is lost at some point, because if I press the button again, the current frame will revert to the old value. After adding some log statements to the button event handler, log output:
before: frame = {{0, 58}, {320, 331}}, contentSize = {320, 1190} update button pressed after: frame = {{0, 0}, {300, 2000}}, contentSize = {300, 2000} before: frame = {{0, 58}, {320, 331}}, contentSize = {320, 1190} update button pressed after: frame = {{0, 0}, {300, 2000}}, contentSize = {300, 2000}
I don’t understand why the frame change is not saved, what changes it.
At some point, I will replace the hard-coded values with the values obtained from the stream layout, but I would like to exclude this and keep my example as simple as possible.
Context: what I want to end up doing is this: I have a scrollable view with various controls, such as labels and images, and a collection view with dynamic content. I want to scroll through all of this, not just view the collection, so I don't use my own scroll viewers that work great.