njdehoog / NHBalancedFlowLayout

UICollectionViewLayout subclass for displaying items of different sizes in a grid without wasting any visual space. Inspired by: http://www.crispymtn.com/stories/the-algorithm-for-a-perfectly-balanced-photo-gallery
MIT License
1.34k stars 106 forks source link

Subclass from UICollectionViewFlowLayout? #13

Closed GalaTech closed 10 years ago

GalaTech commented 10 years ago

For my needs I am really needing to subclass your control directly from UICollectionViewFlowLayout rather than having it be UICollectionViewLayout. I have gotten it to work by just commenting out the sectionInset, minimumLineSpacing, etc. setters, but am not sure if there is a reason why I need to have it subclass from UICollectionViewLayout rather than changing it? Would it be safe to use it this way?

njdehoog commented 10 years ago

I'm not sure I understand what you are trying to achieve. Could you explain what the end result should look like?

GalaTech commented 10 years ago

I apologize for the lack of clarity. I am needing to combine your control with another: https://github.com/lxcid/LXReorderableCollectionViewFlowLayout

I really need your functionality, but I'm also wanting the ability to reorder the collectionView. The problem is that your control subclasses from UICollectionViewLayout and this other control subclasses from UICollectionViewFlowLayout. I need to somehow put them together, but like I said, they subclass from two different superclasses. Is it safe to move yours to subclass from UICollectionViewFlowLayout rather than what is now? In doing so I should have a better base for combining the two classes.

Thanks!

njdehoog commented 10 years ago

Thanks for the explanation. I don't think it will cause any problems if you change the superclass to be UICollectionViewFlowLayout, although I can't make any promises.

The main issue however would seem to be how you would handle resizing of the cells when reordering. Are you planning to recalculate the layout every time the selected cell is dragged to a different position?

GalaTech commented 10 years ago

I appreciate you getting back with me! I actually hadn't looked into how I was planning to fully implement it, but do you think that would be a pretty big problem/is it possible to do it this way?

Thanks!

njdehoog commented 10 years ago

I think it is possible, but I'm not sure how I would implement it. Normally when you reorder items, the items are of the same size, so you don't have to do any resizing. This situation will be a bit trickier to solve, especially if you want to make it look natural. Let me know if you've figured it out though! I would love to see your solution.