表达式类型不明确 | SpringyCollectionViewFlowLayout

Type of expression is ambiguous | SpringyCollectionViewFlowLayout

如本 UICollectionViewFlowlayout 中所述,第 1 步:

// Need to overflow our actual visible rect slightly to avoid flickering.
var visibleRect = CGRectInset(self.collectionView!.bounds, -100, -100)
var itemsInVisibleRectArray: NSArray = super.layoutAttributesForElementsInRect(visibleRect)!
var itemsIndexPathsInVisibleRectSet: NSSet = NSSet(array: itemsInVisibleRectArray.valueForKey("indexPath") as [AnyObject])

// Step 1: Remove any behaviours that are no longer visible.
var noLongerVisibleBehaviours = (self.dynamicAnimator.behaviors as NSArray).filteredArrayUsingPredicate(NSPredicate(block: {behaviour, bindings in
    var currentlyVisible: Bool = itemsIndexPathsInVisibleRectSet.member((behaviour as UIAttachmentBehavior).items.first!.indexPath) != nil
    return !currentlyVisible
}))

"Type of expression is ambiguous without more context" .. 我该怎么办?我真的卡住了:/

感谢您在这方面给我的任何帮助...

如果有人可能只想解决这个问题,请看这里:

    let visibleRect = CGRectInset(self.collectionView!.bounds, -100, -100)
    let itemsInVisibleRect = super.layoutAttributesForElementsInRect(visibleRect)!
    let indexPathsInVisibleRect = Set(itemsInVisibleRect.map({ (attribute) -> NSIndexPath in
        return attribute.indexPath
    }))

    // Step 1: Remove any behaviours that are no longer visible.

    let noLongerVisisbleBehaviors = self.dynamicAnimator.behaviors.filter { (eachBehavior) -> Bool in
        var currentlyVisible = false
        if let behavior = eachBehavior as? UIAttachmentBehavior, first = behavior.items.first as? UICollectionViewLayoutAttributes {
            currentlyVisible = indexPathsInVisibleRect.contains(first.indexPath)
        }
        return !currentlyVisible
    }

值得庆幸的是,这已被证明是当天真正的巨大节省:}