Comments (8)
If anybody meet such a problem too please tell the alternative library please
from alignedcollectionviewflowlayout.
@eli7ah same issue here
from alignedcollectionviewflowlayout.
I was facing same issue. To fix you need invalidateLayout like below:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.collectionView.collectionViewLayout.invalidateLayout()
}
from alignedcollectionviewflowlayout.
I wouldn't recommend invalidating the layout in viewDidLayoutSubviews()
. That method is called when the view has just finished its layout. Invalidating the collection view's layout at that point might trigger a recursion loop.
from alignedcollectionviewflowlayout.
@mischa-hildebrand Ohh..!!! What is an alternative solution to this problem?
from alignedcollectionviewflowlayout.
I honestly don't know. But I'm always open to suggestions!
The problem is the following:
The workflow of AlignedCollectionViewFlowLayout
is that it asks its superclass (UICollectionViewFlowLayout
) for layout attributes (those include the frames / sizes of the cells) and it assumes those layout attributes to be correct. However, Apple has made some changes to the internal layout process which we don't have any control over. For that reason, the superclass methods deliver the wrong layout attributes. (They just have their size set to their estimatedItemSize
, not their actual dynamic size.)
You can confirm this by replacing AlignedCollectionViewFlowLayout
with UICollectionViewFlowLayout
in your project. The same problem should occur.
So for me it seems like it's either of the following two things:
- Either it's simply a system bug introduced by Apple in recent iOS releases.
- Or we're using it incorrectly and Apple expects us to apply a different approach to set it up.
Either way, we can't really do anything about it in this framework. However, please share any hints how to tackle this issue in this thread.
from alignedcollectionviewflowlayout.
💡 Hint:
You can try the following to fix this issue:
-
As the last step in your
viewDidLoad()
method (and subsequently whenever you changed the size of your items), invalidate the flow layout by callingflowLayout?.invalidateLayout()
. -
In your data source method
cellForItem(at:)
, callcell.layoutIfNeeded()
as the last step before returning your configured cell.
While I really don't fancy this solution (it mixes layout with data) and think that it should work out of the box once you plug it in, this method will most likely yield the desired results, without messing with the layout system.
from alignedcollectionviewflowlayout.
if collectionView superView is View Rather than ViewController no viewDidLoad() method .What do I do?
from alignedcollectionviewflowlayout.
Related Issues (20)
- Multiple Section Header Overlapping Cells HOT 2
- UIKit missing when used without CocoaPods
- Any way to keep spacing the same and increase item sizes to justify? HOT 2
- Justify last row HOT 1
- crash in 9iOS HOT 2
- New Release For Right To Left?
- // It's okay to force-unwrap here because we pass a non-empty array. HOT 2
- Horizontal scrolling in single line HOT 1
- No Package.swift manifest for version 1.1.2
- Center Horizontal Alignment
- Multiline text UI is not coming correct.
- Support for SwiftPM HOT 1
- Top Alignment Bug
- Carthage cannot be build HOT 1
- Sometimes items are not rendered HOT 1
- How to prevent cells from being wider than the collection view? HOT 5
- Crash on iPad for iOS 15 HOT 4
- 左对齐,内容过长超出屏幕外。 HOT 1
- ask for help
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alignedcollectionviewflowlayout.