Coder Social home page Coder Social logo

Comments (8)

eli7ah avatar eli7ah commented on May 17, 2024

If anybody meet such a problem too please tell the alternative library please

from alignedcollectionviewflowlayout.

StackHelp avatar StackHelp commented on May 17, 2024

@eli7ah same issue here

from alignedcollectionviewflowlayout.

ivarunpatel avatar ivarunpatel commented on May 17, 2024

I was facing same issue. To fix you need invalidateLayout like below:

   override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        self.collectionView.collectionViewLayout.invalidateLayout()

    }

from alignedcollectionviewflowlayout.

mischa-hildebrand avatar mischa-hildebrand commented on May 17, 2024

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.

ivarunpatel avatar ivarunpatel commented on May 17, 2024

@mischa-hildebrand Ohh..!!! What is an alternative solution to this problem?

from alignedcollectionviewflowlayout.

mischa-hildebrand avatar mischa-hildebrand commented on May 17, 2024

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:

  1. Either it's simply a system bug introduced by Apple in recent iOS releases.
  2. 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.

mischa-hildebrand avatar mischa-hildebrand commented on May 17, 2024

💡 Hint:

You can try the following to fix this issue:

  1. As the last step in your viewDidLoad() method (and subsequently whenever you changed the size of your items), invalidate the flow layout by calling flowLayout?.invalidateLayout().

  2. In your data source method cellForItem(at:), call cell.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.

xiangBiaoOne avatar xiangBiaoOne commented on May 17, 2024

if collectionView superView is View Rather than ViewController no viewDidLoad() method .What do I do?

from alignedcollectionviewflowlayout.

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.