Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

How to subclass UICollectionViewLayoutAttributes and use the custom attributes in your extension? #34

Open
faesa opened this issue Feb 9, 2014 · 7 comments

Comments

@faesa
Copy link

faesa commented Feb 9, 2014

Hi Luke, it's cool to provide such a great extension, thank you!

I successfully implemented it in my project work. In the same way I've tried to add a jiggling effect and a delete button on each cell when the longPress is fired (exactly the same behavior of iPhone's native Springboard).

To do so I've introduced a trigger (isDeletionModeActive) in viewController.m and it is positioned to YES when longPress gesture began.
Then I've subclassed the 2 classes below, for 2 reasons:

  • UICollectionViewLayoutAttributes: for adding a new custom attribute (deletionButtonHidden) triggered via the isDeletionModeActive status the viewController.m
  • UICollectionViewCell: for drawing of delete button and starting a jiggling effect depending on layoutAttributes.isDeleteButtonHidden value
    (you can find more details of the logic here : http://code.tutsplus.com/tutorials/uicollectionview-layouts--mobile-13426)

But the resulting behavior isn't the one I expect as the dragging works (but not as smooth as expected during pan gesture) but the destination cell disappears when I dropped the selected cell on it.

Do you a solution so that I can subclass UICollectionViewLayoutAttributes without affect your extension logic?

Thanks a lot for your help.

@faesa
Copy link
Author

faesa commented Feb 12, 2014

Any answer? ;)

@lukescott
Copy link
Owner

Hi faesa,

It's hard to know what is wrong without debugging it. For the slowness, If I had to guess it probably has something to do with recalculating the layout while dragging conflicting with the animation.

I am currently working on a major project for my work, and it leaves little time for other projects. As you can see I have a bunch of unresolved issues. I do have an experimental (unfinished) rewrite I have yet to publish that may or may not resolve your issue.

I will try to take some time soon to resolve some of the outstanding issues.

@faesa
Copy link
Author

faesa commented Feb 13, 2014

Thanks a lot @lukescott, I'll wait for your future release.

@roiholtzman
Copy link

Hi faesa,
I'm trying to build the same view you built (springboard view with the jiggling effect and draggable cells.
Can you please explain how you inserted this DraggableCollectionView project into you own project? (I believe we have approximately the same Xcode project).

@faesa
Copy link
Author

faesa commented Jun 3, 2014

Hi roiholtzman,
finally I didn't implement the jiggle effect because it is patented by Apple so your app will be rejected for sure if you want to use jiggle effect on cells!
I've only draggable option.
Sorry and good luck.

@roiholtzman
Copy link

Hi faesa,
Thank you very much for the answer. This saved me some time.

@roiholtzman
Copy link

Hi faesa,
I'm don't know how to use this extension with my custom layout. My layout is subclass of UICollectionViewLayout and I already override the method -(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect.
I'm not sure how to put their method of:

  • (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
    {
    return [self.layoutHelper modifiedLayoutAttributesForElements:[super layoutAttributesForElementsInRect:rect]];
    }
    Can you please explain how you did it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants