Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, amazing project! I love how the boxes bounce. There always seems to be one missing - row 0. Anyway, anyone reading this who has a interest in layout should see it! Love the animation.</p> <p>In ...Layout.m:</p> <p>Changed this method to just reload:</p> <pre><code>- (void)removeItemAtIndexPath:(NSIndexPath *)itemToRemove completion:(void (^)(void))completion { //assert([NSThread isMainThread]); UICollectionViewLayoutAttributes *attributes = [self.dynamicAnimator layoutAttributesForCellAtIndexPath:itemToRemove]; [self.collisionBehaviour removeItem:attributes]; [self.gravityBehaviour removeItem:attributes]; [self.itemBehaviour removeItem:attributes]; completion(); [self.collectionView reloadData]; } </code></pre> <p>I added these log messages:</p> <pre><code>- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSLog(@"ASKED FOR LAYOUT ELEMENTS IN RECT"); NSArray *foo = [self.dynamicAnimator itemsInRect:rect]; NSLog(@"...LAYOUT ELEMENTS %@", foo); return foo; } </code></pre> <p>Ran the program and deleted a middle item. Look at the index paths in the console. When you delete an item, you have to reset the index paths, as they now do not properly reflect the cells new indices.</p> <pre><code>CollectionViewDynamics[95862:70b] ASKED FOR LAYOUT ELEMENTS IN RECT CollectionViewDynamics[95862:70b] ...LAYOUT ELEMENTS ( "&lt;UICollectionViewLayoutAttributes: 0x109405530&gt; index path: (&lt;NSIndexPath: 0xc000000000008016&gt; {length = 2, path = 0 - 1}); frame = (105.41 -102.09; 100.18 100.18); transform = [0.99999838000043739, -0.0017999990280001574, 0.0017999990280001574, 0.99999838000043739, 0, 0]; ", "&lt;UICollectionViewLayoutAttributes: 0x10939c2b0&gt; index path: (&lt;NSIndexPath: 0xc000000000018016&gt; {length = 2, path = 0 - 3}); frame = (1 -100.5; 100 100); ", "&lt;UICollectionViewLayoutAttributes: 0x10912b200&gt; index path: (&lt;NSIndexPath: 0xc000000000000016&gt; {length = 2, path = 0 - 0}); frame = (3 468; 100 100); " ) CollectionViewDynamics[95862:70b] *** Assertion failure in -[UICollectionViewData validateLayoutInRect:], /SourceCache/UIKit_Sim/UIKit-2935.80.1/UICollectionViewData.m:357 </code></pre> <p>Fixing that should get you going (I hope). NSLog has been my best friend for years! YMMV</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload