表达的类型不明确SpringyCollectionViewFlowLayout

时间:2016-05-04 06:47:54

标签: ios iphone swift2 uicollectionviewlayout

如本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
}))

"表达的类型是不明确的,没有更多的上下文" .. 我该怎么办?我真的被卡住了:/

感谢您对我的帮助...

1 个答案:

答案 0 :(得分:1)

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

    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
    }

值得庆幸的是,事实证明,这对当天来说是一次真正的巨大拯救:}