Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ASHSpringyCollectionView/ASHSpringyCollectionViewFlowLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ -(void)prepareLayout {

// Step 1: Remove any behaviours that are no longer visible.
NSArray *noLongerVisibleBehaviours = [self.dynamicAnimator.behaviors filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIAttachmentBehavior *behaviour, NSDictionary *bindings) {
BOOL currentlyVisible = [itemsIndexPathsInVisibleRectSet member:[[[behaviour items] firstObject] indexPath]] != nil;
id <UIDynamicItem> item = [[behaviour items] firstObject];
BOOL currentlyVisible = NO;
if ([item isKindOfClass:[UICollectionViewLayoutAttributes class]]) {
currentlyVisible = [itemsIndexPathsInVisibleRectSet member:[(UICollectionViewLayoutAttributes<UIDynamicItem> *)item indexPath]] != nil;
}
return !currentlyVisible;
}]];

[noLongerVisibleBehaviours enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
[self.dynamicAnimator removeBehavior:obj];
[self.visibleIndexPathsSet removeObject:[[[obj items] firstObject] indexPath]];
id <UIDynamicItem>item = [[obj items] firstObject];
if ([item isKindOfClass:[UICollectionViewLayoutAttributes class]]) {
[self.visibleIndexPathsSet removeObject:[(UICollectionViewLayoutAttributes<UIDynamicItem> *)item indexPath]];
}
}];

// Step 2: Add any newly visible behaviours.
Expand Down