Comments (6)
Hey @damienrambout. Thanks for that. I'm not familiar with what UICollectionViewFlowLayout
does under the hood exactly in that case.
This class just hijacks the layoutAttributesForElementsInRect
method on flow layout. I would sort of expect all the sizing to be determined at that point (auto-layout or otherwise). But there are probably differences that we need to account for.
I will investigate when I can. Feel free to dig deeper!
from ktcenterflowlayout.
Thank you very much! I spent the last two days trying to figure out why my swift implementation wasn't working and now I see this post... I came to the exact same conclusion that @damienrambout pointed out. If you come up with something please let me know! I'll do the same.
Cheers!
from ktcenterflowlayout.
One solution, which is not efficient but works, is to use the existing implementation of layoutAttributesForElementsInRect
to implement layoutAttributesForItemAtIndexPath
, by defining a rect that grabs all elements and then just picking out the one you want using its indexPath
, as follows:
override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes! {
let modifiedLayoutAttributes = self.layoutAttributesForElementsInRect(CGRectInfinite)
if let desiredLayAttr = modifiedLayoutAttributes?.filter({ indexPath.isEqual($0.indexPath) }).first as? UICollectionViewLayoutAttributes {
return desiredLayAttr
}
else
{
NSLog("error")
return super.layoutAttributesForItemAtIndexPath(indexPath)
}
}
from ktcenterflowlayout.
Hi guys, I am running into the same issue with auto-layout based cells, but I believe I have come a good way at hunting this down.
When I am laying it out, I don't get the nice spacing I used to before individual cell sizing, I can get to getting nice spacing if I in
func preferredLayoutAttributesFittingAttributes(layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes
just return layoutAttributes
. However, when I have a implementation that returns the size I want, the layout collapses to this:
The really interesting thing is that if I rotate, and then rotate back, I get the expected look:
You can find the project here: https://github.com/skylib/SnapTagsView/tree/DemoForKTCenterFlowLayout and the function referred to above lives in SnapTagsView/SnapTagCell.swift. Just run the example app in it and you'll see exactly what I mean. (you'll need to do a pod install
before compiling it)
Cheers
from ktcenterflowlayout.
thanks @niklassaers i'll check it out
from ktcenterflowlayout.
I'm also noticing that this layout class does not seem to work with auto sizing collection view cells.
Anyone know any alternatives?
from ktcenterflowlayout.
Related Issues (20)
- Cell layout overlap HOT 1
- Still 0.0.2 in cocoapods HOT 2
- iOS9 - UICollectionViewFlowLayout has cached frame mismatch for index path HOT 1
- Autolayout constraints being ignored? HOT 2
- Left alignment. HOT 1
- Support for vertical scroll direction HOT 1
- issue with UICollectionElementKindSectionHeader HOT 2
- self-sizing cells in 1.2 HOT 1
- Fabric crashlytics `layoutAttributesForElementsInRect` crash HOT 1
- when headerAttrs.frame.size is zero,it will be add to updatedAttributes and lead to a crash in IGListKit HOT 3
- Align items to left if content size exceeds bounds HOT 1
- use of unresolved identifier HOT 2
- Support for negative minimumLineSpacing
- Help in using this with swift!!
- Centre cells vertically
- Help to use left align
- iPhone 6Plus weird overlap HOT 17
- Horizontal scrolling HOT 5
- You can add swift version of this beautiful Layout. HOT 1
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 ktcenterflowlayout.