TeehanLax / UICollectionView-Spring-Demo

A demonstration of UICollectionView and UIKit Dynamics
MIT License
471 stars 71 forks source link

Project broken in iOS 9 #19

Open Goles opened 9 years ago

Goles commented 9 years ago

Just for the record, UIAttachmentBehavior does not respond to indexPath.

When trying to build I'm getting:

"No known instance method for selector indexPath" compiler errors.

(maybe you know a way to go around this issue)

DiAvisoo commented 9 years ago

Just do a typecast to UICollectionViewLayoutAttributes where it complains about indexPath:

Example row 67:

Replace

        return [itemsIndexPathsInVisibleRectSet containsObject:
[[[behaviour items] firstObject] indexPath]] == NO;

With the following

        return [itemsIndexPathsInVisibleRectSet containsObject:
[((UICollectionViewLayoutAttributes *)[[behaviour items] firstObject]) indexPath]] == NO;
shantanukhanwalkar commented 9 years ago

Works for me. Should this issue be closed?

yairsz commented 9 years ago

There's a pull request open since June 10 fixing this issue https://github.com/yairsz/UICollectionView-Spring-Demo/commit/1a8e850058fe314ad52eb347c3376a77facea702

albertgh commented 9 years ago

I think it is caused by the new generic feature

// Step 1: Remove any behaviours that are no longer visible.
NSArray *noLongerVisibleBehaviours = [self.dynamicAnimator.behaviors filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIAttachmentBehavior *behaviour, NSDictionary *bindings) {
    UICollectionViewLayoutAttributes *layoutAttr =
    (UICollectionViewLayoutAttributes *)(behaviour.items.firstObject);
    return [itemsIndexPathsInVisibleRectSet containsObject:layoutAttr.indexPath] == NO;
}]];

[noLongerVisibleBehaviours enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
    [self.dynamicAnimator removeBehavior:obj];

    UICollectionViewLayoutAttributes *layoutAttr =
    (UICollectionViewLayoutAttributes *)(((UIAttachmentBehavior *)obj).items.firstObject);

    NSIndexPath *indexPathNeedToRemove = layoutAttr.indexPath;

    [self.visibleIndexPathsSet removeObject:indexPathNeedToRemove];
    [self.visibleHeaderAndFooterSet removeObject:indexPathNeedToRemove];
}];