Giter VIP home page Giter VIP logo

Comments (6)

keighl avatar keighl commented on May 18, 2024

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.

bsantanas avatar bsantanas commented on May 18, 2024

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.

thinalgal avatar thinalgal commented on May 18, 2024

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.

niklassaers avatar niklassaers commented on May 18, 2024

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:

screenshot 2016-02-03 12 27 43

The really interesting thing is that if I rotate, and then rotate back, I get the expected look:

screenshot 2016-02-03 12 27 54

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.

keighl avatar keighl commented on May 18, 2024

thanks @niklassaers i'll check it out

from ktcenterflowlayout.

iliaskarim avatar iliaskarim commented on May 18, 2024

I'm also noticing that this layout class does not seem to work with auto sizing collection view cells.

Anyone know any alternatives? 😅 I'll probably just be left-aligning for now

from ktcenterflowlayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.