openradar-mirror
openradar-mirror copied to clipboard
18078598: UICollectionView calculates contentSize wrong with self-sizing cells
Description
Summary: Using iOS8's self-sizing cells, UICollectionView calculates the size of the cells based on their auto layout constraints. But, as this example shows, it fails to use those numbers to calculate the overall collectionViewContentSize correctly.
This has the effect that some of the collection view's items are laid out beyond the scrollable region of the collection view.
Steps to Reproduce:
- Run the enclosed app, which reproduces the redoubtable Olivier Gutknecht's demo in WWDC 2014, session 226.
- Scroll to the bottom of the collection view.
Expected Results:
- I expected to the see that last collection view item laid out with the others.
Actual Results: 3. Notice that you cannot see the multiline label, which is the last item in the collection view
Version: iOS8beta6
Notes: This included example project includes discussion in the comments in ViewController.swift, and a short video showing the problem in Simulator.app
Configuration: iPhone 5
Attachments: 'SelfSizingCellsDemo.zip' was successfully uploaded.
Attachment available at: https://github.com/algal/SelfSizingCellsDemo/tree/attached-to-radar18078598
Product Version: iOS8beta6 Created: 2014-08-20T19:37:22.663837 Originated: 2014-08-20T00:00:00 Open Radar Link: http://www.openradar.me/18078598
iOS 11 Issue still exists =[
iOS 12 still on 🤞 These features are for WWDC demos only
I ain’t using self sizing cells anymore When I tried using it I waisted weeks of my life for nothing Without it I finished my work in about 2 days! ;)
@ybeapps what did you used instead of the self-sizing cells? I have a similar experience, I'm surprised, how the hackathon-level code goes into system frameworks at @apple.
I wanted the cells to be bigger when selected I gave up on this but as far as I remember I used invalidationContext to add a margin in both sides of the selected cell (in my case the selected cell is always centered)
ב-2 ביולי 2018, בשעה 16:41, Richard Topchii [email protected] כתב/ה:
@ybeapps what did you used instead of the self-sizing cells?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Thanks for reply, but how did you calculate the size and implemented the layout inside the cell? Invalidation context is related to the cell update/reload, where I was mostly interested in the layout technique you've used. Thanks.
I need to check what I’ve done I can’t remember right now I only can say that I didn’t used self-sizing cells mechanism
ב-2 ביולי 2018, בשעה 17:31, Richard Topchii [email protected] כתב/ה:
Thanks for reply, but how did you calculate the size and implemented the layout inside the cell? Invalidation context is related to the cell update/reload, where I was mostly interested in the layout technique you've used. Thanks.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
The last line is clear without any doubt 🤣 I would be really interested in what approach you've used for the layout inside the cells.
My cells are very simple It’s just a UILabel with a number I’m not resizing them, just reposition
When selection changes I call this:
func invalidatePositions() { let ctx = UICollectionViewFlowLayoutInvalidationContext() ctx.invalidateFlowLayoutAttributes = true ctx.invalidateFlowLayoutDelegateMetrics = false invalidateLayout(with: ctx) }
I’m overriding UICollectionViewFlowLayout to achieve what I want with positioning.
And I’m using the power of UICollectionViewDelegate
The delegate and the flowLayout subclasses gives me almost full control on what happening
The cell is very simple, it has nothing special.
ב-2 ביולי 2018, בשעה 19:31, Richard Topchii [email protected] כתב/ה:
The last line is clear without any doubt 🤣 I would be really interested in what approach you've used for the layout inside the cells.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Got it, thanks! My cells are a bit more complex and I don't need to have such level of interactivity. My CollectionView is heterogeneous, similar to AppStore.
Any news on this? Having the same issue.
First load works fine, reloading data with the same data source (after first reloading with a different data source) is sending a bigger or smaller content size, depending on the size of the previous data source, but did not find any rule for it.
My solution was to use the fact that first load always sends correct content size, and I removed and re-added the collection view altogether from and to it's superview, never reload the data, but this is a stupid hack, although it works.
I am curious if anybody finds a correct solution.