Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How can I add UIKit Dynamics to UICollectionViewCells?

I'm trying to incorporate UIKit Dynamics to my implementation of a slide to delete functionality inside UICollectionViewCells. Right now I'm declaring the UIDynamicAnimator in the UICollectionViewController, and the collision, gravity, and push behaviors as properties of the UICollectionViewCell that get configured in the cellForItemAtIndexPath method.

But this is the error I get: View item (<UIView: 0x7fd5e0c398f0; frame = (0 0; 270 94); autoresize = RM+BM; layer = <CALayer: 0x7fd5e0c38030>>) should be a descendant of reference view in <UIDynamicAnimator: 0x7fd5e0e7a9e0> Stopped (0.000000s) in <UICollectionView: 0x7fd5e1046e00> {{0, 0}, {600, 600}}'

Do you know what am I doing wrong? I've been trying to find sample code from other people using this but I couldn't find any. Do you know where I could look at reference material for it?

Thanks!

1 Answer

UIKit Dynamics are designed to work a little bit differently with UICollectionViews. Here's an awesome article on how to do it right